User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,499 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 468 | Replies: 1
Reply
Join Date: Aug 2007
Posts: 21
Reputation: rime is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rime rime is offline Offline
Newbie Poster

Help please help with the following code

  #1  
Sep 6th, 2007
I have written the following code and I want that when a user doesn't fill his first name and mothertongue then it'll show the error message. But whats happening is that after showing the alert for the FirstName alert its directly going to the MotherTongue box. Its not even allowing to fill the LastName before MotherTongue is filled. Why is this happening? Please help me to overcome the problem.

details.html

<html>
<head>
<script>
function ff1()
{
if(document.f1.FirstName.value=='' || document.f1.MotherTongue.value=='Mother Tongue'){
alert("Please enter your First Name");
document.f1.FirstName.focus();
return false;}

if(document.f1.MotherTongue.value=='' || document.f1.MotherTongue.value=='Mother Tongue'){
alert("Please enter your Mother Tongue");
document.f1.MotherTongue.focus()
return false;}
return true;

}
</script>
</head>
<form method="post" action="filenext.php" name="f1" onBlur="ff1()>
Name :
<input name="FirstName" type="text" class="dropmenu" id="FirstName" value="First Name" size="15" maxlength="30" onBlur="ff1()"/>
<input name="LastName" type="text" class="dropmenu" id="LastName" value="Last Name" size="20" maxlength="30"/><br />
Mother Tongue :
<input name="MotherTongue" type="text" class="dropmenu" id="MotherTongue" value="Mother Tongue" size="20" maxlength="30" />

<input name="submit" type=submit class="button" value="submit" />
</form>
</html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Argentina
Posts: 83
Reputation: martin5211 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
martin5211's Avatar
martin5211 martin5211 is offline Offline
Junior Poster in Training

Re: please help with the following code

  #2  
Sep 6th, 2007
mmm I see... Please, in the future use code tags when you post code to get more clear.
The problem is in the conditions. If you use OR, when one is true, returns ever true value. If you use AND, the two values should be true to execute the intrinsical methods.
Use complete headers with doctype, then use W3C validator. Note the use of getElementById, it is another method.
Also, you could split the ff1() in two functions, and call each condition in accordance with the id element if there are problems later.

<html>
<head>
<script>
function ff1()
{
if(document.getElementById('FirstName').value==""){
alert("Please enter your First Name");
document.getElementById('FirstName').focus();
}

if(document.getElementById('MotherTongue').value==""){
alert("Please enter your Mother Tongue");
document.getElementById('MotherTongue').focus()
}


} 
</script>
</head>
<form method="post" action="validation.php">
Name :
<input name="FirstName" type="text" class="dropmenu" id="FirstName" value="First Name" size="15" maxlength="30" onblur="ff1()" />
<input name="LastName" type="text" class="dropmenu" id="LastName" value="Last Name" size="20" maxlength="30"/><br />
Mother Tongue :
<input name="MotherTongue" type="text" class="dropmenu" id="MotherTongue" value="Mother Tongue" size="20" maxlength="30" onblur="ff1()" />

<input name="submit" type="submit" class="button" value="submit" />
</form>
</html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC