473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form Validation Problem.

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.

Apr 4 '07 #1
3 1426
On Apr 4, 4:06 pm, davidjcam...@gmail.com wrote:
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

Apr 4 '07 #2
On Apr 4, 4:06 pm, davidjcam...@gmail.com wrote:
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

Apr 4 '07 #3
On Apr 4, 9:22 am, "Darko" <darko.maksimo...@gmail.comwrote:
On Apr 4, 4:06 pm, davidjcam...@gmail.com wrote:


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- Hide quoted text -

- Show quoted text -

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

Apr 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
6
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.