Forum Moderators: open
I am looking to add a value to a text input when someone clicks a checkbox. I currently can disable the textbox but I wanted to add a value to it first so when the form is processed it can pass the value along. My hope is the have the text box hold the value called "Fill".
<input type="checkbox" onclick="document.getElementById('thebox').disabled=(this.checked)?1:0">
<input type="textbox" id="thebox">
The text box will normally be open to anything they want to type. But if they click the check box we force the value and lock it. Make sense?
Thanks,
J Colgate
<script type="text/javascript">
window.onload = function () {
// Attach event handlers
var cb = document.getElementById('theCheckBox');
var thebox = document.getElementById('thebox');
cb.onclick = function () {
if (cb.checked) {
thebox.value = '****';
}
thebox.readonly = cb.checked;
};
};
</script>
<input type="checkbox" id="theCheckBox">
<input type="text" id="thebox">