jophab jophab - 1 year ago 83
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.


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;

<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">

Answer Source

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


Also, you must close your radios with the closing tag

<input type="radio" name="i" />click
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download