Your code seems to be incorrect. Have a look at the following code that will do what you are looking for
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Demo Page</title>
<style type="text/css">
</style>
<script type="text/javascript">
function resetField(name,value){
document.forms['form'].elements[name].focus();
document.forms['form'].elements[name].value = value;
}
</script>
</head>
<body>
<form name="form">
<input type="text" name="adjustment1" size="10" value="10.0" />
<input type="text" name="adjustment2" size="10" value="15.0" />
<input type="text" name="adjustment3" size="10" value="12.0" />
<input type=button value="reset field" onclick="resetField('adjustment2','0.0');" />
</form>
</body>
</html>
In the above code you can see that there is a JavaScript function named 'resetField' that accepts two parameters:
(1) The name of the form field which you want to change.
(2) The new value for the to be changed element.
In the button's onclick event we call the function and pass 'adjustment2' in other words we need to replace whatever value inside the 'adjustment2' form field with '0.0'. Please note that if you pass 0.0 without using any quotes then it will be consdered as numeric type and when the value comes in the form field the decimal point section will be removed. So I've treated it as a string for the time being.
You've mentioned that you've tried to use 'reset' field for this job and it clear all the form fields. Actually the functionality of this is resetting the form element, which is not suitable for your job as you've mentioned.
You can also extend the script in such a manner that you can reset a number of fields to a single value or to different values also.
Please let me know if you need any more help on this thing.
Bookmarks