W
Willie
I have a script that I want to check the checkbox if something is writen in
a text field. Then uncheck it if it erased.
The check works but not the uncheck.
Here is the code:
String.prototype.trim =
function()
{
return this.replace(/^\s+|\s+$/g,'');
}
function mark(fn, textfield, checkbox){
var check = (document.forms[fn][checkbox]);
var text = (document.forms[fn][textfield]);
text = text.value.trim();
if(text.value != ""){
checkbox.checked = 'true';
}
if(text.value == ""){
checkbox.checked = 'false';
}
}
in the form :
<input type="text" name="RepID"
onChange="mark('f1','RepID',this.form.checkbox)">
a text field. Then uncheck it if it erased.
The check works but not the uncheck.
Here is the code:
String.prototype.trim =
function()
{
return this.replace(/^\s+|\s+$/g,'');
}
function mark(fn, textfield, checkbox){
var check = (document.forms[fn][checkbox]);
var text = (document.forms[fn][textfield]);
text = text.value.trim();
if(text.value != ""){
checkbox.checked = 'true';
}
if(text.value == ""){
checkbox.checked = 'false';
}
}
in the form :
<input type="text" name="RepID"
onChange="mark('f1','RepID',this.form.checkbox)">