473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I added a function, then the rest of the script are not working..

Hi, this is a code for form verification... I added the function results() then the entire script is now not working. Need help... *note that if I omit the results() function, other functional parts (disabling other text field) are working...

Need help thanks...

P.S.
the omitted/commented codes were my attempt of trying to debug the program... XD

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>HTML DOM Exercise</title>
  4.         <script type="text/javascript">
  5.             var er=0;
  6.             var s=0;
  7.             function tmp()
  8.                 {
  9.                     document.getElementById("perm1").readOnly=true;
  10.                     document.getElementById("perm2").readOnly=true;
  11.                     document.getElementById("perm3").readOnly=true;
  12.                     document.getElementById("perm4").readOnly=true;
  13.                     document.getElementById("perm5").readOnly=true;
  14.                     document.getElementById("perm6").readOnly=true;
  15.                     document.getElementById("temp1").readOnly=false;
  16.                     document.getElementById("temp2").readOnly=false;
  17.                     document.getElementById("temp3").readOnly=false;
  18.                     document.getElementById("temp4").readOnly=false;
  19.                     document.getElementById("temp5").readOnly=false;
  20.                     document.getElementById("temp6").readOnly=false;
  21.                     document.getElementById("temp7").readOnly=false;
  22.                     s=0;
  23.                 }
  24.             function prm()
  25.                 {
  26.                     document.getElementById("perm1").readOnly=false;
  27.                     document.getElementById("perm2").readOnly=false;
  28.                     document.getElementById("perm3").readOnly=false;
  29.                     document.getElementById("perm4").readOnly=false;
  30.                     document.getElementById("perm5").readOnly=false;
  31.                     document.getElementById("perm6").readOnly=false;
  32.                     document.getElementById("temp1").readOnly=true;
  33.                     document.getElementById("temp2").readOnly=true;
  34.                     document.getElementById("temp3").readOnly=true;
  35.                     document.getElementById("temp4").readOnly=true;
  36.                     document.getElementById("temp5").readOnly=true;
  37.                     document.getElementById("temp6").readOnly=true;
  38.                     document.getElementById("temp7").readOnly=true;
  39.                     s=1;
  40.                 }
  41.             function results()
  42.                 {
  43.                     //var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; 
  44.                     if(s===0)
  45.                         {
  46.                             if((isNaN(document.getElementById("temp1").value))
  47.                                 {
  48.                                 //document.getElementById("temp1").style.color:rgb(252,113,105);
  49.                                  document.getElementById("error").innerHTML += "Home Number should be a Number! <br>"; er=1;
  50.                                  }
  51.                             if(document.getElementById("temp2").value=="" || document.getElementById("temp2").value==null )
  52.                                 {
  53.                                 //document.getElementById("temp2").style.color:rgb(252,113,105);
  54.                                  document.getElementById("error").innerHTML += "Street is a Mandatory Field! <br>";er=1;
  55.                                  }
  56.                             if(document.getElementById("temp3").value=="" || document.getElementById("temp3").value==null )
  57.                                 {
  58.                                 //document.getElementById("temp3").style.color:rgb(252,113,105);
  59.                                  document.getElementById("error").innerHTML += "City is a Mandatory Field! <br>";er=1;
  60.                                  }
  61.                             if(document.getElementById("temp4").value=="" || document.getElementById("temp4").value==null)
  62.                                 {
  63.                                 //document.getElementById("temp4").style.color:rgb(252,113,105);
  64.                                  document.getElementById("error").innerHTML += "State is a Mandatory Field! <br>";er=1;
  65.                                  }
  66.                             if(document.getElementById("temp5").value=="" || document.getElementById("temp5").value==null )
  67.                                 {
  68.                                 //document.getElementById("temp5").style.color:rgb(252,113,105);
  69.                                  document.getElementById("error").innerHTML += "Zip Code is a Mandatory Field! <br>";er=1;
  70.                                  }
  71.                             if(document.getElementById("temp6").value=="" || document.getElementById("temp6").value==null )
  72.                                 {
  73.                                 //document.getElementById("temp6").style.color:rgb(252,113,105);
  74.                                  document.getElementById("error").innerHTML += "Street is a Mandatory Field! <br>";er=1;
  75.                                  }
  76.                             else if(isNaN(document.getElementById("temp6").value))
  77.                                 {
  78.                                 //document.getElementById("temp6").style.color:rgb(252,113,105);
  79.                                  document.getElementById("error").innerHTML += "Zip Code should be a Number! <br>";er=1;
  80.                                  }
  81.                             else if(document.getElementById("temp6").length>5 || document.getElementById("temp6").length<3)
  82.                                 {
  83.                                 //document.getElementById("temp6").style.color:rgb(252,113,105);
  84.                                  document.getElementById("error").innerHTML += "Zip code should be 3 to 5 digits long! <br>";er=1;
  85.                                  }
  86.                         }
  87.                     else
  88.                         {
  89.                             if(isNaN(document.getElementById("perm1").value)
  90.                                 {
  91.                                 //document.getElementById("perm1").style.color:rgb(252,113,105);
  92.                                  document.getElementById("error").innerHTML += "Home Number should be a Number! <br>";er=1;
  93.                                  }
  94.                             if(document.getElementById("perm2").value=="" || document.getElementById("perm2").value==null )
  95.                                 {
  96.                                 //document.getElementById("perm2").style.color:rgb(252,113,105);
  97.                                  document.getElementById("error").innerHTML += "Street is a Mandatory Field! <br>";er=1;
  98.                                  }
  99.                             if(document.getElementById("perm3").value=="" || document.getElementById("perm3").value==null )
  100.                                 {
  101.                                 //document.getElementById("perm3").style.color:rgb(252,113,105);
  102.                                  document.getElementById("error").innerHTML += "City is a Mandatory Field! <br>";er=1;
  103.                                  }
  104.                             if(document.getElementById("perm4").value=="" || document.getElementById("perm4").value==null )
  105.                                 {
  106.                                 //document.getElementById("perm4").style.color:rgb(252,113,105);
  107.                                  document.getElementById("error").innerHTML += "State is a Mandatory Field! <br>";er=1;
  108.                                  }
  109.                             if(document.getElementById("perm5").value=="" || document.getElementById("perm5").value==null )
  110.                                 {
  111.                                 //document.getElementById("perm5").style.color:rgb(252,113,105);
  112.                                  document.getElementById("error").innerHTML += "Zip Code is a Mandatory Field! <br>";er=1;
  113.                                  }
  114.                             if(document.getElementById("perm6").value=="" || document.getElementById("perm6").value==null )
  115.                                 {
  116.                                 //document.getElementById("perm6").style.color:rgb(252,113,105);
  117.                                  document.getElementById("error").innerHTML += "Street is a Mandatory Field! <br>";er=1;
  118.                                  }
  119.                             else if(isNaN(document.getElementById("perm6").value))
  120.                                 {
  121.                                 //document.getElementById("perm6").style.color:rgb(252,113,105);
  122.                                  document.getElementById("error").innerHTML += "Zip Code should be a Number! <br>";er=1;
  123.                                  }
  124.                             else if(document.getElementById("perm6").length>5 || document.getElementById("perm6").length<3)
  125.                                 {
  126.                                 //document.getElementById("perm6").style.color:rgb(252,113,105);
  127.                                  document.getElementById("error").innerHTML += "Zip code should be 3 to 5 digits long! <br>";er=1;
  128.                                  }
  129.                             // if(document.getElementById("perm7").value != '' && !document.getElementById("perm6").innerHTML(re)) 
  130.                                 {
  131.                                 //document.getElementById("perm7").style.color:rgb(252,113,105);
  132.                                 // document.getElementById("error").innerHTML += "Invalid Date Format! <br>";er=1;
  133.                                  }
  134.                         }
  135.                     if(er==0)
  136.                         {
  137.                             alert("Succesful!")
  138.                         }
  139.                     else
  140.                         {
  141.                             er=0;
  142.                         }
  143.                     }
  144.                 }
  145.         </script>
  146.     </head>
  147.     <body>
  148.         <p id="error">&nbsp</p>
  149.         <form name="Selector">
  150.             <input type="radio" onClick="prm()" name="add" value="Perm" /> Permanent Address<br />
  151.             <input type="radio" onClick="tmp()" name="add" value="Temp" /> Temporary Address<br />
  152.         </form>
  153.         <div class="perm">
  154.             <table>
  155.                 <form name="Permanent">
  156.                     <tr><td colspan="4">Permenent Address: &nbsp;</td></tr>
  157.                     <tr><td>House Number</td><td>Street*</td><td>City*</td></tr>
  158.                     <tr><td><INPUT id="perm1" TYPE="text"   NAME="Hnum"></td><td><INPUT id="perm2" TYPE="text"   NAME="Street"></td><td><INPUT id="perm3" TYPE="text"   NAME="City"></td></tr>
  159.                     <tr><td>State*</td><td>Country*</td><td>Zip*</td></tr>
  160.                     <tr><td><INPUT id="perm4" TYPE="text"   NAME="State"></td><td><INPUT id="perm5" TYPE="text"   NAME="Country"></td><td><INPUT id="perm6" TYPE="text"   NAME="Zip"></td></tr>
  161.                 </form>
  162.             </table>
  163.         </div>
  164.         <br><br>
  165.         <div class="temp">
  166.             <table>
  167.                 <form name="Temporary">
  168.                     <tr><td colspan="4">Temporary Address: &nbsp;</td>
  169.                     <tr><td>House Number</td><td>Street*</td><td>City*</td><td></td></tr>
  170.                     <tr><td><INPUT id="temp1" TYPE="text"   NAME="Hnum"></td><td><INPUT id="temp2" TYPE="text"   NAME="Street"></td><td><INPUT id="temp3" TYPE="text"   NAME="City"></td><td></td></tr>
  171.                     <tr><td>State*</td><td>Country*</td><td>Zip*</td><td>Date*</td></tr>
  172.                     <tr><td><INPUT id="temp4" TYPE="text"   NAME="State"></td><td><INPUT id="temp5" TYPE="text"   NAME="Country"></td><td><INPUT id="temp6" TYPE="text"   NAME="Zip"></td><td><INPUT id="temp7" TYPE="text"   NAME="Date">&nbsp; mm/dd/yyyy</td></tr>
  173.                 </form>
  174.             </table>
  175.         </div>
  176.         <br><br>
  177.         <input type="button" onClick="results()" value="Submit"/>
  178.     </body>
  179. </html>
Sep 7 '10 #1
3 1469
RamananKalirajan
608 512MB
In ur code line number 44. It must be if(s==0) not if(s===0).
In Line No 47 add additional closing paranthesis at the end ")"
Line No 90 add additional closing paranthesis at the end ")"
Remove the Additional Brace at Line no 145

Due to this the function was not working.

Thanks and Regards
Ramanan Kalirajan
Sep 7 '10 #2
still not working...

EDIT... ok ok... now its working... thanks... i wasted 1 hour just looking for a missing ')'... XD

Thanks again
Sep 7 '10 #3
gits
5,390 Expert Mod 4TB
one note:

it is a difference in checks when using:

Expand|Select|Wrap|Line Numbers
  1. if (s == 0)
or:

Expand|Select|Wrap|Line Numbers
  1. if (s === 0)
both are working but the second will even do a typecheck (identity operator), which in the shown case would require that the value of s would be a number, while in the first an implicit typecast is made so even '' == 0 or ' ' == 0 would return true. so basically you should need to know what you want to check ... and it shouldn't need have to be a reason for the non-working script in the first place.

kind regards
Sep 7 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: guillaume | last post by:
hello from france, I want to edit a list of customers dynamically and each row contains an input text with the name of customer and link to update the name the link calls the javascript ...
2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
0
by: serkan | last post by:
Guys, I am trying to get this password reset functionality wor for me but I am not successful at all. Please somebody help me. I get "Your password could not be reset - please try again later" so I...
4
by: deedi | last post by:
Hi, I'm writing a code which calls the javascript function through button click in ASP. But i fear , the function is executed before onclick. Here is my code. <html> <body> <%asp code...
4
by: sivapriyan | last post by:
Hello, My java script function is working well in IE but not in Firefox My javascript is function visible() {...
4
by: shivendravikramsingh | last post by:
hi friends,i have facing a problem,when i m calling a function on onLoad event of Body,function is not working.but if i call this function on any other event like onblur etc. it work fine.but my...
4
AMT India
by: AMT India | last post by:
This JS function is not working in IE 6 and 7.. function ValidateRows( checkbox_id ){ if( document.pageform.eval(checkbox_id).value){ if (...
4
by: itgaurav198 | last post by:
Hi, I have the following two problems. 1. The following script is Working in IE and not in Mozilla Firefox i.e. it si not setting the value of the textbox. <input type="text" name="notify">...
12
by: robin1983 | last post by:
hi everyone, i m very new to Ajax, and this is my first program in Ajax. I dont know what is wrong in the script. Please help me to find out the error, The main error is the value that i suppose to...
2
by: riddhibhatia | last post by:
Hie....my set_cookie function is not working. I dont know why it is happening as there is no error also...i am setting it through javascript....... var live_element; function fokus(ele,path) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.