+ 2

Why language.length is giving 0?What is wrong in this code ? I was expecting language.lenth = 2.

https://code.sololearn.com/WF8Yq0RIRZ02/?ref=app

26th Apr 2020, 11:07 AM
Ankur Singh Oli
Ankur Singh Oli - avatar
7 Respuestas
+ 2
Remove that document.write which is creating problem used before var language This is what is happening https://www.w3schools.com/jsref/met_doc_write.asp
26th Apr 2020, 11:19 AM
Abhay
Abhay - avatar
+ 3
window.onsubmit = function() { var skill = document.getElementsByName("skill"); var message = "You selected -" for(var i=0;i<skill.length;i++){ if(skill[i].checked){ message = message + " " + skill[i].value }; }; var language = document.getElementsByName('language'); var message1 = "<br/>Language -" for(var j=0;j<language.length;j++){ if(language[j].checked){ message1 = message1 + " " + language[j].value }; }; document.write(message ,message1 ); };
26th Apr 2020, 11:25 AM
Cmurio
Cmurio - avatar
+ 3
Thanks everyone. You are awesome.
26th Apr 2020, 11:43 AM
Ankur Singh Oli
Ankur Singh Oli - avatar
+ 2
Abhay is right: document.write cause an implicite document.open() wich reset all your document content, so after writing, there's zero elements of name 'language' to be selected ^^
26th Apr 2020, 11:21 AM
visph
visph - avatar
+ 1
visph Thanks once again. One related question, when a form is submitted, if I want to show some graph or pie chart or something, to the client based on his/her input,which tools do I need?
26th Apr 2020, 12:06 PM
Ankur Singh Oli
Ankur Singh Oli - avatar
+ 1
you could handle it on client side, by your own, or using some dedicated js library: https://www.sitepoint.com/best-javascript-charting-libraries/
26th Apr 2020, 12:08 PM
visph
visph - avatar
+ 1
Thanks for sharing the link, it is very helpful.
26th Apr 2020, 12:14 PM
Ankur Singh Oli
Ankur Singh Oli - avatar