Click to See Complete Forum and Search --> : problem with checkbox and setting focus


rjusa
11-11-2003, 12:24 AM
Here's what I'm trying to accomplish:

I have a checkbox and when checked, sets selected field (as they gain focus) with a highlighted background...I hardcoded individual fields so I know the highlighting works...here's what I've tried:

<SCRIPT LANGUAGE="JavaScript">

var kolor = "$kolor$";
function SetFKolor(FKolor) {
document.forms[0].kolor.value=FKolor;
}
</script>

onmouseup="SetFKolor('highlight')"

onFocus="kolor(event)"

I'm stuck! Any thoughts would be appreciated.

Thanks,
Ron

Charles
11-11-2003, 04:42 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label, textarea {display:block; margin:1em 0em}
input {margin:0 1ex}
.highlight {background-color:#aaa; color:#fff}
-->
</style>

<form action="">
<div>
<label><input type="checkbox" onclick="if (this.checked) {this.form.other.className = 'highlight'; this.form.other.focus()} else {this.form.other.className = ''; this.form.other.value = ''}">Other</label>
<textarea id="other"></textarea>
<button type="submit">Submit</button>
</div>
</form>