HTML/JS help, Cannot find error |
HTML/JS help, Cannot find error |
skyward |
Feb 16 2016, 02:16 AM
Post
#1
|
Group: Members Posts: 7 Joined: 16-February 16 Member No.: 23,998 |
Hi
I am absolutely new to html and javascript. I have developed a simple form in html that is checked through a js function through an onClick event. The problem is that the function is not being executed although there does not seem to be any errors. i have checked it through the w3school debugger and firebug but i am really confused because i DON'T KNOW whats wrong. I need urgent help with this and will appreciate any pointers. thanks here is the code <!DOCTYPE html> <HTML> <HEAD> <title>Online Job Portal</title> <script type="text/javascript"> function checkForm() { document.write("Working"); var chk=true; var name=document.getElementById("fullname").value; var age=document.getElementById("getage").value; var under=document.getElementById("under").checked; var grad=document.getElementById("grad").checked; if(name==""){ chk=false; window.alert("Name is required");} if(isNaN(age)||age<1||age>100){ chk=false; window.alert("Enter Valid Age");} if(under==false && grad==false){ chk=false; window.alert("Select Qualification");} if(chk==false){ document.getElementById("info").innerHTML="Please give your information correctly";} if (chk==false){ var qual=document.getElementById("under").checked; var it=document.getElementById("it").checked; var marketing=document.getElementById("marketing").checked; var academics=document.getElementById("academics").checked; if(qual==true){ qual="Undergraduate";} else{ qual="Graduate";} if (it==true){ it="IT";} else{ it="None";} if (marketing==true){ marketing="Marketing";} else{ marketing="None";} if (academics==true){ academics="Academics";} else{ academics="None";} document.getElementById("info").innerHTML= "Hello"+fullname<br> "Your age is "+age" years"<br> "Your qualification is" + qual<br> "Your selected job types are"<br> "Job 1 :" + it<br> "Job 2 :" + marketing<br> "Job 3 :" + academics<br>; } } </script> </HEAD> <BODY> <form name="job portal" action=""> <h1>Online Job Portal</h1> <TABLE> <tr> <td>Name :</td> <td><input type="text" id="fullname" name="fullname" value=""></td> </tr> <tr> <td>Age :</td> <td><input type="text" id="getage" name="getage" value=""></td> </tr> <tr> <td>Qualification :</td> <td>UnderGraduate<input type="radio" name="qualification" id="under" value="undergraduate"></td> <td>Graduate<input type="radio" name="qualification" id="grad" value="graduate"></td> </tr> <tr> <td>Select a job type :</td> <td>IT<input type="checkbox" name="selectJobType" id="it" value="it"></td> <td>Marketing<input type="checkbox" name="selectJobType" id="marketing" value="marketing"></td> <td>Academics<input type="checkbox" name="selectJobType" id="academics" value="academics"></td> </tr> </TABLE> <br> <br> <br> <br> <div id="info"> </div> <input type="button" value="Show Information" onClick="checkForm()"> <input type="reset" value="Reset Form"> </form> </BODY> </HTML> |
pandy |
Feb 16 2016, 05:29 AM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,734 Joined: 9-August 06 Member No.: 6 |
You seem to have a brace too many at the end of the script.
The closing brace is missing here. CODE if (chk==false){ var qual=document.getElementById("under").checked; var it=document.getElementById("it").checked; var marketing=document.getElementById("marketing").checked; var academics=document.getElementById("academics").checked; The quotes are screwed up in the string. HTML tags must be quoted too and you had missed a quote altogether. You can't have line breaks in the middle of strings either, you must place those at the plus signs. CODE document.getElementById("info").innerHTML = 'Hello' +fullname + '<br> Your age is ' + age + ' years <br> Your qualification is' + qual + '<br> Your selected job types are <br> Job 1 :' + it + '<br> Job 2 :' + marketing + '<br> Job 3 :' + academics +'<br>'; The object is returned instead of the value for fullname. Afraid I don't see why. But otherwise it works with those corrections. |
pandy |
Feb 16 2016, 05:58 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,734 Joined: 9-August 06 Member No.: 6 |
Oh, I changed to single quotes out of habit. It doesn't matter for functionality if you use single or double.
|
Lo-Fi Version | Time is now: 8th May 2024 - 06:41 PM |