0

I tried using this

<input type="text" name="commentID" id="commentID" onkeyup="userTyped('skipID', this)"/>
<input type="checkbox" name="skipID" value="N" id="skipID" checked="checked"  />

and the javascript

function userTyped(commen, e){
if(e.value.length > 0){
document.getElementById(commen).checked=false;
}else{
document.getElementById(commen).checked=true;
}}​

It works on JSfiddle, "EXAMPLE" but i can't seem to make it work on dreamweaver, and only if I use one textbox, I want the checkbox to be unchecked automatically only after three textbox is filled.

user1852728
  • 161
  • 2
  • 6
  • 13

1 Answers1

0

Here http://jsfiddle.net/MAVLy/7/ is a rewritten function using jQuery with three textboxes. For readability I put textbox length in variables but you could omit that.

HTML:

<input type="text" name="textbox1" id="textbox1" class="enable" />
<input type="text" name="textbox2" id="textbox2" class="enable" />
<input type="text" name="textbox3" id="textbox3" class="enable" />
<input type="checkbox" name="skipID" value="N" id="skipID" checked="checked"  />

JQUERY:

$(function(){
  $('input.enable').keyup(function(){
    var t1 = $('#textbox1').val().length;
    var t2 = $('#textbox2').val().length;
    var t3 = $('#textbox3').val().length;
   if (t1==0 || t2==0 || t3==0) $('#skipID').attr('checked', true);
   else $('#skipID').attr('checked', false);
  });        
});

Alternative solution. This one applies to unlimited numbers of textboxes of the class enable

$(function(){
  $('input.enable').keyup(function(){
    var checked = false;
    $('input.enable').each(function(){
       if ($(this).val().length == 0) checked = true;
    });
    $('#skipID').attr('checked', checked);
  });        
});

Another jsfiddle: http://jsfiddle.net/MAVLy/8/

jtheman
  • 7,421
  • 3
  • 28
  • 39