jophab jophab - 6 months ago 14
HTML Question

Text field appearing with along radio buttons, where my form does not have a text input

enter image description here
This is the output of my code. I have no text inputs but I am seeing text inputs along with radio buttons when I run this.

<script>

function validateForm() {
var x = document.forms["myForm"][0].value;
if (x == null || x == "") {
alert("i must be checked");
return false;
}
var y = document.forms["myForm"][1].value;
if (y == null || y == "") {
alert("j must be checked");
return false;
}
var z = document.forms["myForm"][2].value;
if (z == null || z == "") {
alert("k must be checked");
return false;
}
}
</script>

<body>
<form name="myForm" onsubmit="return validateForm()">
<input type="radio" name="i">click<input/>
<input type="radio"name="j">click<input/>
<input type="radio"name="k">click<input/>
<input type="submit" value="submit">
</form>
</body>

Answer

You are using these empty input tags in the end of each radio, input tag by default renders as text box

<input/>

Also, you must close your radios with the closing tag

<input type="radio" name="i" />click
Comments