Jump to content

Help with Javascript in a php page


BinaryBird

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/205464-help-with-javascript-in-a-php-page/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.