The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> HTML/JS help, Cannot find error
skyward
post 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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Feb 16 2016, 08:46 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,665
Joined: 10-August 06
Member No.: 7



Could you post the corrected version as well?
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
skyward
post Feb 16 2016, 08:51 AM
Post #3





Group: Members
Posts: 7
Joined: 16-February 16
Member No.: 23,998



QUOTE(Christian J @ Feb 16 2016, 08:46 AM) *

Could you post the corrected version as well?


<!DOCTYPE html>
<HTML>
<HEAD>
<title>Online Job Portal</title>

<script type="text/javascript">

function checkForm()
{
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==true){
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"+name+
"<br>Your age is "+age" years"+
"<br>Your qualification is" + qual+
"<br>Your selected job types :"+
"<br>Job 1 :" + it+
"<br>Job 2 :" + marketing+
"<br>Job 3 :" + academics;

}
</script>
</HEAD>
<BODY>
<form name="job portal">
<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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 16 2016, 09:38 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,734
Joined: 9-August 06
Member No.: 6



Here.
QUOTE(skyward @ Feb 16 2016, 02:51 PM) *

CODE
document.getElementById("info").innerHtml=



Should be:

CODE
document.getElementById("info").innerHTML=


It's case sensitive, like everything JavaScript. wink.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 16 2016, 09:39 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,734
Joined: 9-August 06
Member No.: 6



Bummer. blush.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
skyward
post Feb 16 2016, 09:53 AM
Post #6





Group: Members
Posts: 7
Joined: 16-February 16
Member No.: 23,998



QUOTE(pandy @ Feb 16 2016, 09:39 AM) *

Bummer. blush.gif



DOOOOONNNNNEEEEE

Happy to say I found those last errors....though a few hours ago i was ready to give up when u guys gave me the boost.........U were right @Pandy.....the code works fine even in the Head.....don't know what I did to correct it smile.gif......

its just a code ...why am i so happy smile.gif

Thanks a lot Pandy and Christain.... and that was a good competition u both had smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 16 2016, 01:49 PM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,734
Joined: 9-August 06
Member No.: 6



Christian is always doing that. Lurks while I do all the hard work then he jumps in with the finishing touch. I feel aso used! IPB Image happy.gif

Did you retype something when you moved the script? That's usually how one screws up.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 16 2016, 03:14 PM
Post #8


.
********

Group: WDG Moderators
Posts: 9,665
Joined: 10-August 06
Member No.: 7



Usually it's pandy that posts first while I'm busy spell checking. sad.gif


User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 16 2016, 04:36 PM
Post #9


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,734
Joined: 9-August 06
Member No.: 6



No! Not the final solution. I often miss some detail and then come you... ninja.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
skyward
post Feb 17 2016, 12:58 AM
Post #10





Group: Members
Posts: 7
Joined: 16-February 16
Member No.: 23,998



QUOTE(pandy @ Feb 16 2016, 04:36 PM) *

No! Not the final solution. I often miss some detail and then come you... ninja.gif



I think the main issue was the innerHtml typo... and the braces (turns out the braces were fine originally)...and the quotes..... blush.gif .lol....small mistakes but i wonder why they went undetected in the debuggers?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 17 2016, 02:51 AM
Post #11


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,734
Joined: 9-August 06
Member No.: 6



What do you mean by originally? The braces weren't fine in your original post, but innerHTML was written correctly.

What debugger missed the braces and the quotes? Maybe you used the HTML validator. It doesn't check JavaScript.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
skyward
post Feb 17 2016, 07:51 AM
Post #12





Group: Members
Posts: 7
Joined: 16-February 16
Member No.: 23,998



QUOTE(pandy @ Feb 17 2016, 02:51 AM) *

What do you mean by originally? The braces weren't fine in your original post, but innerHTML was written correctly.

What debugger missed the braces and the quotes? Maybe you used the HTML validator. It doesn't check JavaScript.



They were logically ok, but I might have mistyped(as in wrong place) one of them, because I put them back where I thought I had out them originally and thats when the code worked perfectly, along with the innerHtml typo.

Yes I used the Html validator because I didn't know it won't check the JavaSript huh.gif wacko.gif ...I also used Firebug. A far as I could understand there were no errors from Firebug, but it was hard to understand the interface blush.gif .

I was pretty much banging around on my own. Thank God I decided to post the issue here otherwise I would ave been at it for the next week smile.gif. Made a brand-new account for that sole purpose:)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
skyward   HTML/JS help   Feb 16 2016, 02:16 AM
pandy   You seem to have a brace too many at the end of th...   Feb 16 2016, 05:29 AM
pandy   Oh, I changed to single quotes out of habit. It do...   Feb 16 2016, 05:58 AM
Christian J   The object is returned instead of the value for f...   Feb 16 2016, 05:58 AM
pandy   Duh. I just realized fullname was used in the stri...   Feb 16 2016, 06:04 AM
skyward   Duh. I just realized fullname was used in the str...   Feb 16 2016, 08:35 AM
Christian J   Could you post the corrected version as well?   Feb 16 2016, 08:46 AM
skyward   Could you post the corrected version as well? ...   Feb 16 2016, 08:51 AM
skyward   YAAAY Its running...only partially but running......   Feb 16 2016, 09:08 AM
pandy   It shouldn't make any difference in this case....   Feb 16 2016, 09:20 AM
Christian J   Try using your browser's script console, it sh...   Feb 16 2016, 09:34 AM
pandy   Here. [code]document.getElementById("info...   Feb 16 2016, 09:38 AM
pandy   Bummer. :blush:   Feb 16 2016, 09:39 AM
skyward   Bummer. :blush: DOOOOONNNNNEEEEE Happy to sa...   Feb 16 2016, 09:53 AM
pandy   Christian is always doing that. Lurks while I do a...   Feb 16 2016, 01:49 PM
Christian J   Usually it's pandy that posts first while I...   Feb 16 2016, 03:14 PM
pandy   No! Not the final solution. I often miss some ...   Feb 16 2016, 04:36 PM
skyward   No! Not the final solution. I often miss some...   Feb 17 2016, 12:58 AM
pandy   What do you mean by originally? The braces weren...   Feb 17 2016, 02:51 AM
skyward   What do you mean by originally? The braces weren...   Feb 17 2016, 07:51 AM
pandy   What do you mean by originally? The braces weren...   Feb 17 2016, 01:28 PM
Christian J   Christian, has FF removed the old JS console, or ...   Feb 17 2016, 03:57 PM
pandy   I don't get any of those things to show me JS ...   Feb 17 2016, 06:11 PM
Christian J   I don't get any of those things to show me JS...   Feb 17 2016, 07:03 PM
pandy   Click on the Console tab, and JS if necessary. Bu...   Feb 18 2016, 01:11 AM
pandy   FYI I don't find anything useful in Iron eithe...   Feb 18 2016, 01:17 AM
Christian J   Does Chrome have an error console? Yes. Since...   Feb 18 2016, 05:59 AM
pandy   Since there can be unique errors in a buggy brows...   Feb 18 2016, 07:55 AM
Christian J   Click on the Console tab, and JS if necessary. B...   Feb 18 2016, 05:53 AM
pandy   [quote name='pandy' post='115847' date='Feb 18 20...   Feb 18 2016, 07:54 AM
Christian J   No, I haven't installed any extensions. Fireb...   Feb 18 2016, 08:23 AM
pandy   Yes, all debuggers require reloading if they weren...   Feb 18 2016, 11:33 AM
pandy   Wait, it works now. I added a line break in the st...   Feb 18 2016, 11:37 AM
pandy   It does. Both tools, but they report just one erro...   Feb 18 2016, 11:58 AM
CharlesEF   It does. Both tools, but they report just one err...   Feb 18 2016, 12:25 PM
Christian J   My browser's script console didn't spot th...   Feb 17 2016, 08:40 AM
pandy   Yes, I think so. I didn't get an error for tha...   Feb 17 2016, 01:21 PM
CharlesEF   I use Firefox with Firebug installed also. It has...   Feb 17 2016, 08:20 PM
CharlesEF   If we are talking about the same thing then yes, i...   Feb 18 2016, 02:43 AM
pandy   If we are talking about the same thing then yes, ...   Feb 18 2016, 07:56 AM
pandy   If we are talking about the same thing then yes, ...   Feb 18 2016, 08:12 AM
Christian J   Didn't get far. Don't get any superscript...   Feb 18 2016, 08:24 AM
CharlesEF   Christian is correct. If you turn on Firebug afte...   Feb 18 2016, 11:08 AM
CharlesEF   FYI, according to the Firebug help forum all brows...   Feb 19 2016, 12:56 AM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 9th May 2024 - 02:51 PM