BinaryBird Posted June 21, 2010 Share Posted June 21, 2010 Hi, i am trying to validate a form field using javascript in a php page. But its not working. Here is the code : <?php session_start(); $pvt_id = session_id(); //if(isset($_POST['submit'])) { $_SESSION['name'] = 'Jester'; $_SESSION['id'] = $pvt_id ; //echo $id; //} ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Validation</title> <script language="JavaScript" src="gen_validatorv31.js" type="text/javascript"></script> </head> <body> <form id="createaccount" name="createaccount" action="register.php" method="post" > ID:<input type="text" name="id" id="id" size="30" value="" /> <input style="width:19em" id="submit" name="submit" type="submit" value='Validate' /> </form> <script language="JavaScript" type="text/javascript"> var frmvalidator = new Validator("createaccount"); frmvalidator.addValidation("id","req","Please enter your ID") frmvalidator.addValidation("id","maxlen=10","Max length for ID is 10"); </script> </body> </html> Please find the js code attached. Am i missing something here? Kindly help me. Thanks. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/205464-help-with-javascript-in-a-php-page/ Share on other sites More sharing options...
Psycho Posted June 21, 2010 Share Posted June 21, 2010 The fact that the page is PHP has nothing to do with the problem. Your PHP code is only setting a couple of variables and have no effect on the HTML page sent to the browser. You are apparently using some 3rd party script for doing your validation. I'm not really interested in trying to decypher 800+ lines of code to figure out why it doesn't work. This forum is for helping people with code they have written. Why don't you ask the author of that script why it isn't working. have you done ANY debugging to track down the problem to at least determine the specific function(s) in that script are causing the problem? All that being said, I would suggest changing the name and id of the field from "id" to anything else. "id" is a reserved word and should not be used for a form field if you want to reference in JS. Quote Link to comment https://forums.phpfreaks.com/topic/205464-help-with-javascript-in-a-php-page/#findComment-1075234 Share on other sites More sharing options...
BinaryBird Posted June 21, 2010 Author Share Posted June 21, 2010 I will change the id , thanks for the suggestion. I have tried that with other forms and it worked. Maybe it is due to the id. Anyways let me check. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/205464-help-with-javascript-in-a-php-page/#findComment-1075251 Share on other sites More sharing options...
BinaryBird Posted June 21, 2010 Author Share Posted June 21, 2010 Tried to change the id. Still not working. It worked perfectly for an other form. Not this one. Not sure why. But that was just a html page. If any one could suggest what could be wrong, would be great. I am basically trying to make sure that a value is entered in the field before the user submits it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/205464-help-with-javascript-in-a-php-page/#findComment-1075262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.