Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox

Status
Not open for further replies.

ptichka

Programmer
May 28, 2002
19
US
Hi everybody,

I am pretty new at using JavaScript. SO I have having a bit of a problem.

I have a list of checkboxes, which are named dynamically with values from the database. I also have a list of radio buttons which have values which match the names of the corresponding checkbox. (I know..a little confusing...sorry)

So what I need to happen is this:

When a user selects a radio button, I need the corresponding checkbox to become checked.

This is what I have so far...it's probably completely of base:
function setcheck(form) {
for (var i=0; i<form.DefaultDash.length; i++) {
if (form.DefaultDash.checked){
var checkboxname = form.DefaultDash.value;
alert(document.forms[0].eval("check_"+checkboxname+".name"));
document.forms[0].eval("check_"+checkboxname+".name").checked = true;
break
}
}
}
 
Kind of hard to help without an HTML sample. Are you getting errors? Here are a few suggestions:

-Use .name instead of .value to get the checkbox name.
-Don't use eval.

Try something like this:

Code:
function setcheck(form) {
  for (var i=0; i<form.DefaultDash.length; i++) {
    if (form.DefaultDash[i].checked){
      var checkboxname = form.DefaultDash[i].value;
      alert(form.elements['check_' + checkboxname].name);
      form.elements['check_' + checkboxname].checked = true;
    }
  }
}

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Thanks so much.
Your suggestion worked perfect!!!
 
wow, nice. :)

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top