Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 06-23-2005, 12:53 AM Validation function
waller's Avatar
Skilled Talker

Posts: 59
Location: North Borneo.
Trades: 0
PHP Code:
html>

<
head>
<
script type="text/javascript">
function 
formSubmit()
{
x=document.forms.myForm
fname
=x.firstname.value.replace(/:/g,"")
lname=x.lastname.value.replace(/:/g,"")

var 
num1=parseInt(fname)
var 
num2=parseInt(lname)

if (
fname<lname){
alert (lname)
return 
false
}
else if (
fname>lname){
alert (fname)
return 
false
}
else{
return 
true
}

}
</script>
</head>

<body>
<form name="myForm" action="message5.htm" method="post">
Firstname: <select name="firstname" size="1"> <option>00:00:00</option> <option>00:30:00</option>
 <option>01:00</option>  <option>01:30</option>
 <option>02:00</option></select>
<br />
                            
Lastname: <select name="lastname" size="1">
<option>00:00:00</option> <option>00:30:00</option>
 <option>01:00</option>  <option>01:30</option>
 <option>02:00</option></select>
<br /><br />
<input type="submit" onclick="formSubmit()" value="Submit">
</form>
</body>

</html> 
Above is my code. in the line
PHP Code:
<form name="myForm" action="message5.htm" method="post"
we know that if this form is validated by the function, it will be directed to
message5.htm . Unfortunately, no matter if it is true or false, it will still be directed to
message5.htm . Where is the error?
__________________
$id ="waxxer";
$id = str_replace('x', 'l', $id);
echo $id;
echo " and Marj";
waller is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2005, 09:57 AM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
Instead of using the submit button's onClick event, try using the same code but with the form's onSubmit event.
__________________

Please login or register to view this content. Registration is FREE
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 06-23-2005, 12:09 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
And you have to place "return" infront of it.
HTML Code:
<form name="myForm" action="message5.htm" method="post" onsubmit="return formSubmit();">
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Validation function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37988 seconds with 12 queries