+ 2
Why language.length is giving 0?What is wrong in this code ? I was expecting language.lenth = 2.
7 ответов
+ 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
+ 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 );
};
+ 3
Thanks everyone.
You are awesome.
+ 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 ^^
+ 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?
+ 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/
+ 1
Thanks for sharing the link, it is very helpful.