Hi I have several text input boxes, and i have a clear button, they all share the same name and i wish to clear them all using one function, and this be done without ID’s as that takes up too much space
my code thus far looks like this:
var Id;
var Name;
function Check(id, name) {
Id = document.getElementById(id);
Name = document.getElementById(name);
if (Id.value == id) {
Name.checked = true;
alert('correct');
return;
} else {
Name.checked = false;
alert('incorrect');
}
}
function ClearP() {
document.getElementsByName("input").innerHTML = '';
}
my html looks like this
<div class="content">
<div class="main_story" style="margin-bottom:20px;">
<p class="sentence">the word to go here -></p>
<input id="here" name="input" class="sentence" type="text" size="7">
<p class="sentence">is here</p>
<button style="float:right" id="correct" onClick="Check('here', 'aShow');">Correct?</button>
<input style="float:right" name="aShow" id="aShow" type="checkbox" value="">
</div>
<div class="main_story" style="margin-bottom:20px;">
<p class="sentence">the word to go here -></p>
<input id="you" name="input" class="sentence" type="text" size="7">
<p class="sentence">is you</p>
<button style="float:right" id="correct" onClick="Check('you', 'bShow');">Correct?</button>
<input style="float:right" name="bShow" id="bShow" type="checkbox" value="">
</div>
<button onClick="ClearP();">Clear</button>
</div>
all help is much appreciated 🙂 thank you 🙂
1 Answer