Form Validation Problem.

D

davidjcampos

I'm a definite newbie to javascript, but I have put together some
workable code from several different examples on the web. I am using
both "onchange" event handlers as well as an "onsubmit" event
handler. The "onchange" event handlers are working great. When a
user enters an amount that is greater then the amount of vacation time
they actually have, a message pops up letting them know that they must
enter a smaller amount. Along with this, I would like to use a simple
"onsubmit" event handler that basicially checks the same thing that
the "onchange" event handler does, but prevents the form from being
submitted if the amount entered is incorrect. Here is my "onsubmit"
event handler that is not working. Even if an invalid amount is
entered it still submits the form.

<script type="text/javascript" language="JavaScript">

function validateSubmitInput()
{
userInput = new String();
userInput = this.form1.txtCompTime.value;

var JSCompTimeBalance = "<%= CompTimeBalance %>"
var JSCompTimeTextBox = document.form1.txtCompTime.value

if (parseFloat(JSCompTimeTextBox) > parseFloat(JSCompTimeBalance))
{
alert("There is a problem");
return false;
}

return true;

}
</script>


<form name="form1" method="post" action="Timesheet3_Sent.asp"
ONSUBMIT="validateSubmitInput();">
<input name="txtCompTime" type="text" class="TextboxSmaller"
id="txtCompTime" value="0" onChange= "validateInput(this.value)();">
</form>

Any help would be appreciated.
 
D

Darko

I'm a definite newbie to javascript, but I have put together some
workable code from several different examples on the web. I am using
both "onchange" event handlers as well as an "onsubmit" event
handler. The "onchange" event handlers are working great. When a
user enters an amount that is greater then the amount of vacation time
they actually have, a message pops up letting them know that they must
enter a smaller amount. Along with this, I would like to use a simple
"onsubmit" event handler that basicially checks the same thing that
the "onchange" event handler does, but prevents the form from being
submitted if the amount entered is incorrect. Here is my "onsubmit"
event handler that is not working. Even if an invalid amount is
entered it still submits the form.

<script type="text/javascript" language="JavaScript">

function validateSubmitInput()
{
userInput = new String();
userInput = this.form1.txtCompTime.value;

var JSCompTimeBalance = "<%= CompTimeBalance %>"
var JSCompTimeTextBox = document.form1.txtCompTime.value

if (parseFloat(JSCompTimeTextBox) > parseFloat(JSCompTimeBalance))
{
alert("There is a problem");
return false;
}

return true;

}

</script>

<form name="form1" method="post" action="Timesheet3_Sent.asp"
ONSUBMIT="validateSubmitInput();">
<input name="txtCompTime" type="text" class="TextboxSmaller"
id="txtCompTime" value="0" onChange= "validateInput(this.value)();">
</form>

Any help would be appreciated.

Make it this way: onsubmit="return validateSubmitInput();"

Cheers
 
D

Darko

I'm a definite newbie to javascript, but I have put together some
workable code from several different examples on the web. I am using
both "onchange" event handlers as well as an "onsubmit" event
handler. The "onchange" event handlers are working great. When a
user enters an amount that is greater then the amount of vacation time
they actually have, a message pops up letting them know that they must
enter a smaller amount. Along with this, I would like to use a simple
"onsubmit" event handler that basicially checks the same thing that
the "onchange" event handler does, but prevents the form from being
submitted if the amount entered is incorrect. Here is my "onsubmit"
event handler that is not working. Even if an invalid amount is
entered it still submits the form.

<script type="text/javascript" language="JavaScript">

function validateSubmitInput()
{
userInput = new String();
userInput = this.form1.txtCompTime.value;

var JSCompTimeBalance = "<%= CompTimeBalance %>"
var JSCompTimeTextBox = document.form1.txtCompTime.value

if (parseFloat(JSCompTimeTextBox) > parseFloat(JSCompTimeBalance))
{
alert("There is a problem");
return false;
}

return true;

}

</script>

<form name="form1" method="post" action="Timesheet3_Sent.asp"
ONSUBMIT="validateSubmitInput();">
<input name="txtCompTime" type="text" class="TextboxSmaller"
id="txtCompTime" value="0" onChange= "validateInput(this.value)();">
</form>

Any help would be appreciated.

Make it this way: onsubmit="return validateSubmitInput();"

Cheers
 
D

davidjcampos

Make it this way: onsubmit="return validateSubmitInput();"

Cheers- Hide quoted text -

- Show quoted text -


Thank you very much! That did the trick! Many thanks to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top