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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.