To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-05-2006, 06:18 AM   #1
fibonacci
Member
 
Join Date: May 2006
Posts: 37
Javascript problem: form validation

heyya..

i got a problem with my javascript form validation..
i have no idea what is the problem as i think i have written the right javascript code..

PHP Code:
<?php

    
require 'f:/www/digitallibrary/conf/config.inc.php';    
    require
'f:/www/digitallibrary/conf/smarty.inc.php';    
    
    
?>

<? $html->display('header.html') ?>

<script language="javascript">

function validate_form(form){
        
    if(form.name.value==" " && form.password.value==" "){
        alert("Fill out ALL fields.");
        return false;
    }
    return true;
}

</script>


<form name="login" method="post" action="checklogin.php" onsubmit="return validate_form(this)";>


<?
if (isset($_GET['e'])  )
{
echo
"<font color='red'><b>Wrong Username and Password</b></font>";
}
?>

<table>
<tr>
<td colspan="2"> &nbsp; </td>
</tr>
<tr>
<td colspan="2"> &nbsp; </td>
</tr>
<tr>
<td colspan="2"><b> Login</b></td>
</tr>
<tr>

<td>Username : </td>
<td><input type="text" name="username" id="username" size="15" /></td>
</tr>
<tr>
<td>Password : </td>
<td><input type="password" name="password" id="password" size="15" /></td>
</tr>
<tr>
<td colspan="2"> &nbsp; </td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Login" /></td>
</tr>
<tr>
<td colspan="2"> &nbsp; </td>
</tr>
<tr>
<td colspan="2"><h5><a href=#> Forget Your Username and Password? </a></h5></td>
</tr>
</table>

</form>


<? $html->display('footer.html') ?>
is there anything wrong with my javascript code?
anyone can give me a hand?
thanks in advance...
fibonacci is offline   Reply With Quote
Old 05-05-2006, 06:35 AM   #2
esukf
Senior Member
 
Join Date: Apr 2006
Posts: 174
PHP Code:
<script language="javascript">

function
validate_form(form){
         
    if(
form.username.value=="" || form.password.value==""){
        
alert("Fill out ALL fields.");
        return
false;
    }
    return
true;
}

</script>
esukf is offline   Reply With Quote
Old 05-05-2006, 06:55 AM   #3
fibonacci
Member
 
Join Date: May 2006
Posts: 37
hi..
thanks esukf it works..!!

anyway, if u don't mind
can u explain what is the different between || and &&

thanks
fibonacci is offline   Reply With Quote
Old 05-05-2006, 07:17 AM   #4
Houdini
Lost in Time (1970's)
 
Houdini's Avatar
 
Join Date: Jul 2004
Location: Nashville TN USA
Posts: 1,932
Quote:
if(form.name.value==" " && form.password.value==" "){
Should be
HTML Code:
if(form.username.value=="" && form.password.value==""){
|| is the OR and of course && is AND. Had you used || If either the password OR the name been blank it would have given the Alert. Using AND both have to be blank to get the Alert so your logic actually need to be to work correctly.
HTML Code:
if(form.username.value=="" || form.password.value==""){
To test and see what I mean enter anything even a space into the username and the script will not show the Alert and carry on to the PHP script.

Last edited by Houdini; 05-05-2006 at 07:25 AM.
Houdini is offline   Reply With Quote
Old 05-05-2006, 07:27 AM   #5
esukf
Senior Member
 
Join Date: Apr 2006
Posts: 174
Deleted

Last edited by esukf; 05-05-2006 at 07:31 AM. Reason: Already excellently explained by houdini
esukf is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 05:37 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.