944,196 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 706
  • PHP RSS
Sep 6th, 2007
0

please help with the following code

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rime is offline Offline
24 posts
since Aug 2007
Sep 6th, 2007
0

Re: please help with the following code

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.

PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script>
  4. function ff1()
  5. {
  6. if(document.getElementById('FirstName').value==""){
  7. alert("Please enter your First Name");
  8. document.getElementById('FirstName').focus();
  9. }
  10.  
  11. if(document.getElementById('MotherTongue').value==""){
  12. alert("Please enter your Mother Tongue");
  13. document.getElementById('MotherTongue').focus()
  14. }
  15.  
  16.  
  17. }
  18. </script>
  19. </head>
  20. <form method="post" action="validation.php">
  21. Name :
  22. <input name="FirstName" type="text" class="dropmenu" id="FirstName" value="First Name" size="15" maxlength="30" onblur="ff1()" />
  23. <input name="LastName" type="text" class="dropmenu" id="LastName" value="Last Name" size="20" maxlength="30"/><br />
  24. Mother Tongue :
  25. <input name="MotherTongue" type="text" class="dropmenu" id="MotherTongue" value="Mother Tongue" size="20" maxlength="30" onblur="ff1()" />
  26.  
  27. <input name="submit" type="submit" class="button" value="submit" />
  28. </form>
  29. </html>
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Traffic Exchange
Next Thread in PHP Forum Timeline: OOP Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC