Forum Moderators: open
You can use the onclick event from the submit button, and then reset and leave the values you wish using the DOM.
Something like this:
function resetOnlyThese(){
document.forms[0].elements["mytextbox"].value == "";
}
<input type="submit" onclick="resetOnlyThese()" value="Reset">
HTH,
-gs
<input type="button" value="Rest" onclick="resetOnlyThese">
function resetOnlyThese(){
document.forms[0].elements["textbox1"].value == "";
document.forms[0].elements["textbox2"].value == "";
document.forms[0].elements["textbox3"].value == "";
}
Let's know if that works for you?
-gs
<html>
<head><title></title>
<script language=javascript>
function resetOnlyThese(){
document.getElementById('textbox1').value = "";
document.getElementById('textbox2').value = "";
document.getElementById('textbox3').value = "";
}
</script>
</head>
<body>
<form>
<input type="text" id="textbox1"><br>
<input type="text" id="textbox2"><br>
<input type="text" id="textbox3"><br>
<input type="text" id="textbox4">
<input type="button" value="Reset" onclick="resetOnlyThese()">
</form>
</body>
</html>
This example will clear the contents of the first 3 text boxes and leave the 4th one alone.
HTH,
-gs
Thank you in advance for your help.
-foshae :o)
To reset some to their "original" use the defaultValue property. For radio controls, you have to work with the radio "group" i.e., the radios that are collectively under the same name.
fumction resetRadios(oRadGrp){
for(var i = 0;i < oRadGrp.length;iu++) oRadGrp[i].value = oRadGrp[i].defaultValue;
}
var selOneIndex = 2
function resetSelect(oSel){
oSel.selectedIndex=selOneIndex
}
In responce to mylungsareempty, I agree that you do not need a "reset" button for short forms. However, the one I am creating is very long and has multiple sections to it. Giving the end-user the option to clear specific sections of the form creates a "user-friendly" interface. :o)