|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I want to check the empty text in the form with javascript and php. What's wrong in this program? How to solve it? Thanks!
<html> <script language="javascript"> <!-- option_desc=new makearray(<? echo $num-1; ?> ); function checkform() { <? for ($i=0; $i<$num; $i++) { ?> if (document.poll_form.option_desc[<? echo $i; ?>].value=="") { alert("Text<? echo $i+1; ?> is empty."); document.poll_form.option_desc[<? echo $i; ?>].focus(); return false; } <? } ?> return true; } //--> </script> <body> <form method="post" action="" name="poll_form" onsubmit="return checkform();"> <? for ($i=0; $i<$num; $i++) { ?> <p> <input type="text" name="option_desc[<? echo $i; ?>]" size="50"> </p> <? } ?> <input type="submit" name="submit"> </form> </body> </html> [This message has been edited by RayRay (edited June 16, 2000).] |
|
#2
|
||||
|
||||
|
The javascript routine is client side - the onSubmit() executes client side before the form is posted and therfore before the values in option_desc[] exist-
if you send the page to itself via the form ,then validation will occur but your validation routine runs before the form is actually submitted. onSubmit() return true; - will only send the form & post the variables if the validation was successful. If you see what I mean? Simon ------------------ Simon Wheeler FirePages -DHTML/PHP/MySQL |
|
#3
|
|||
|
|||
|
Now, is the javascript doesn't work. It can't validation the text data.
How to solve it? |
|
#4
|
||||
|
||||
|
Hi RayRay - listen - apologies my last answer was gibberish - not sure where I was coming from - the form below works!
<html> <script language="javascript"> <!-- function checkform() { <?php $num=3;?> <? for ($i=0; $i<$num; $i++) { ?> if (document.poll_form.option_desc<? echo $i; ?>.value=="") { alert("Text<? echo $i+1; ?> is empty."); document.poll_form.option_desc<? echo $i; ?>.focus(); return false; } <? } ?> return true; } //--> </script> <body> <form method="post" action="#" name="poll_form" onsubmit="return checkform();"> <? for ($i=0; $i<$num; $i++) { ?> <p> <input type="text" name="option_desc<? echo $i; ?>" size="50"> </p> <? } ?> <input type="submit" name="submit"> </form> </body> </html> The problem was making option_value[] a javascript array - Now it is a PHP one and it works fine!!!! Still not sure what I was thinking the first time? Simon ------------------ Simon Wheeler FirePages -DHTML/PHP/MySQL |
|
#5
|
||||
|
||||
|
I must be on something today ! -
"The problem was making option_value[] a javascript array - Now it is a PHP one and it works " option_value is no longer an array of any sort! ------------------ Simon Wheeler FirePages -DHTML/PHP/MySQL |
|
#6
|
|||
|
|||
|
Thank you very much!
|
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Javascript with PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|