2 Replies - 717 Views - Last Post: 19 January 2011 - 11:29 AM

#1 ans2007kumar  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

Javascript not working

Posted 18 January 2011 - 10:05 AM

My java script of validation is not working don't know why

here is the code

Header php file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<link rel="stylesheet" type="text/css" href="c.css" />
<title>simple document</title>
<script src="validate.js;cart.js">

</script>
<script type=" text/javascript">
<?php
 session_start();
?>
</script>
</head>
<body>
<div align="center" class="none" style=" width: 100%;">
<table class="none" width="100%">
<tr>
<td>
<img src="images/main_banner.jpg" height="150"/><br/>
</td> 
<td>
<?php   
$s=$_SESSION['id']; 
if($s==null)
{
echo'
<form name="login" action="login_check.php" method="post">
<table class="none" border="2px solid" style="height: 150px; width: 100px;">
<tr>
<td width="40px">
UserName:
</td>
<td width="40px">
<input class="login" type="text" name="user" />
</td>
</tr>
<tr>
  <td width="40px">
Password:
</td>
<td width="40px">
<input  class="login" type="password" name="pass" />
</td>
</tr>
<tr>
<td>
 <input class="login" value="Login" type="submit" name="login" />
</td> 
<td>  
 <a class="none" style="color:black; font-weight: bold ;" href="reg.php">Register</a>
</td>
</tr>
</table>
</form>'; 
}
else
{
 echo '<div><h4>Welcome  '.$_SESSION['Name'] .'</h4></div><br/>';   
echo '<a href="logout.php">Logout</a>';
}   
?> 
 
</td>
  
</tr>  
</table>
</div>
 
<br/>
<div align="justify" width="80%">
<table>
<tr>
<td>
<a href="home.php">Home</a>
</td>
<td>
<a href="kids.php">Kids Wear</a>
</td>
<td>
<a href="mens.php">Mens Wear</a>
</td>
<td>
<a href="women.php">Women Wear</a>
</td>

</tr>
</table>
</div>


SCRIPT
function req(field,alertmsg)
{
    with(field)
    {
        if(value==null||value=="")
        {
            alert(alertmsg);
            return false;
        }
        else
        {
            return true;
        }
        
    }
}
function compare(field1,field2)
{
    var val1
    var val2;
    with(field1)
    {
        val1=value;
    }
    with(field2)
    {
        val2=value;
        if(val1!=val2)
        {
            alert(" Do not Match ");
            return false;
            
        }
        else
        {
            return true;
        }
    }
}
function validate(thisform)
     {
         with(thisform)
         {
              if(req(un,"User name must be filled")==false)
              {
                   un.focus();return false;
              }
              if(req(pass,"Enter the Password")==false)
              {
                  pass.focus();return false;
              }
              if(req(pass1,"Enter the Password again")==false)
              {
                  pass1.focus();return false;
              }
               
               if(req(credit,"Cerdit Card Number must be filled")==false)
              {
                   credit.focus();return false;
              }
              if(req(email,"Valid Email-ID must be filled")==false)
              {
                   email.focus();return false;
              }
              if(req(email1,"Enter Email-ID again")==false)
              {
                   email1.focus();return false;
              }
               if(req(name,"Name filled cannot be Empty")==false)
              {
                   name.focus();return false;
              }
               if(req(add,"Address must be filled")==false)
              {
                   add.focus();return false;
              }
               if(req(city,"City must be filled")==false)
              {
                   city.focus();return false;
              }
              if(req(pin,"Pin Code must be filled")==false)
              {
                   pin.focus();return false;
              }
               if(req(state,"State must be filled")==false)
              {
                   state.focus();return false;
              }                  
               if(req(coun,"Country must be filled")==false)
              {
                   coun.focus();return false;
              }
              if(req(mob,"Phone number must be filled")==false)
              {
                   mob.focus();return false;
              }
              
              if(compare(email,email1)==false)
              {                             
                   email1.focus();  return false; 
              }
              if(compare(pass,pass1)==false)
              {
                   pass1.focus(); return false;   
              }
         }    
     }


REGISTRATION PAGE
<?php
$title = "Welcome";               
include ("head.php");   
?>  
<br/>

<form action="register.php" method="post" onsubmit="return validate(this)">//here where i call it

<div class="none" align="center" style="width: 80%;">
<table class="reg" style="font-weight: bold;">
<tr>
<td>
User Name:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="un">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<INPUT class="reg" TYPE="password" NAME="pass">
</td>
</tr>
<tr>
<td>
Confirm Password:
</td>
<td>
<INPUT class="reg" TYPE="password" NAME="pass1">
</td>
</tr>
<tr>
<td>
Cerdit Card No:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="credit">
</td>
</tr>
<tr>
<td>
Email-Id:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="email">
</td>
</tr>
<tr>
<td>
Confirm Email-Id:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="email1">
</td>
</tr>
<tr>
<td>
Full Name:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="name">
</td>
</tr>
<tr>
<td>
Address:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="add">
</td>
</tr>
<tr>
<td>
City:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="city">
</td>
</tr>
<tr>
<td>
PinCode:
</td>
<td>
<INPUT  class="reg" TYPE="text" NAME="pin">
</td>
</tr>
<tr>
<td>
State:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="state">
</td>
</tr>
<tr>
<td>
Country:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="coun">
</td>
</tr>
<tr>
<td>
Phone Number:
</td>
<td>
<INPUT class="reg" TYPE="text" NAME="mob">
</td>
</tr>
<tr></tr>
<tr>
<td align="center">
<input class="button"  type="reset">
</td>
<td align="center">
<input class="button" type="submit" value="Submit">
</td>
</tr>
</table>

</div>
</form>
</body>
</html>

This post has been edited by Dormilich: 18 January 2011 - 10:16 AM
Reason for edit:: moved to JavaScript Forum, not a PHP issue


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript not working

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3524
  • View blog
  • Posts: 10,164
  • Joined: 08-June 10

Re: Javascript not working

Posted 18 January 2011 - 10:23 AM

with() is an easy way to get into trouble. the error console should have some clues, why it doesn’t work.
Was This Post Helpful? 0
  • +
  • -

#3 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Javascript not working

Posted 19 January 2011 - 11:29 AM

<script src="validate.js;cart.js">



I am quite certain you can't put more than one URL in your src attribute like that..... Also, why are you opening a Javascript tag to open php tags inside and start a session??

This post has been edited by Dormilich: 19 January 2011 - 01:14 PM
Reason for edit:: grammar

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1