...

View Full Version : check a radio button when a textbox is populated



vavavince
09-20-2005, 07:18 PM
i was wondering if it could be possible to mark a radio button as "checked" if the textbox beside it is clicked, or populated? Thanks..

rwedge
09-20-2005, 08:08 PM
Here's an example:

<script type="text/javascript">
<!--
/*<![CDATA[*/
function bstatus(t,x) {
(x>0)? document.getElementById(t).checked=true:
document.getElementById(t).checked=false;
}
/*]]>*/
// -->
</script>


<form name="f" id="f" method="post" action="" enctype="application/x-www-form-urlencoded">
<input type="text" name="t1" id="t1" value="" size="35" maxlength="300" onchange="bstatus('rb1',this.value.length)" />
<input type="radio" name="rb1" id="rb1" />
<br /><input type="text" name="t2" id="t2" value="" size="35" maxlength="300" onchange="bstatus('rb2',this.value.length)" />
<input type="radio" name="rb2" id="rb2" />
</form>

CrAzY_J
09-20-2005, 08:54 PM
Here's an example:

<script type="text/javascript">
<!--
/*<![CDATA[*/
function bstatus(t,x) {
(x>0)? document.getElementById(t).checked=true:
document.getElementById(t).checked=false;
}
/*]]>*/
// -->
</script>


<form name="f" id="f" method="post" action="" enctype="application/x-www-form-urlencoded">
<input type="text" name="t1" id="t1" value="" size="35" maxlength="300" onchange="bstatus('rb1',this.value.length)" />
<input type="radio" name="rb1" id="" />
<br /><input type="text" name="t2" id="t2" value="" size="35" maxlength="300" onchange="bstatus('rb2',this.value.length)" />
<input type="radio" name="rb2" id="rb2" />
</form>

You use document.getElementById and grab the first argument, but the value you provide as the first argument when calling the function is a name and not a Id :P



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum