By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Accesing object properties programatically

P: 1
I have an event where attendants can register for online. This is 2 day event. I want to be able to disable the same lab on day2 when it has been selected on day1 (so attendants don't select the same lab on two different days).
This is the function I am using...

[HTML]function DisableOther(a){
var myD = a.name.substring(4, 5);
var myS = a.name.substring(6, 7);
var othD;
if (myD == 1){
othD = '2';
} else {
othD = '1';
}
var b = eval("document.frm01." + a.name);
var c = findButton(b);
eval("document.frm01.optD" + othD + "S" + myS + "[" + c + "].disabled = true");
if (c == 0){
eval("document.frm01.optD" + othD + "S" + myS + "[" + (c + 1) + "].disabled = false");
} else {
eval("document.frm01.optD" + othD + "S" + myS + "[" + (c - 1) + "].disabled = false");
}
}
function findButton(buttonGroup){
for (i=0; i < buttonGroup.length; i++) {
if (buttonGroup[i].checked == true) {
return i;
}
}
}

<input type="radio" name="optD1S1" id="optD1S1" value="D1S1-1" onClick="DisableOther(this)" />
<input type="radio" name="optD1S1" id="optD1S1" value="D1S1-2" onClick="DisableOther(this)" />
<input type="radio" name="optD2S1" id="optD2S1" value="D2S1-1" onClick="DisableOther(this)" />
<input type="radio" name="optD2S1" id="optD2S1" value="D2S1-2" onClick="DisableOther(this)" />[/HTML]

I know I shouldn't use eval but I don't know how to access the properties of the radio button group.
The above code is working on IE but not working on FF, any ideas??
Thanks...
Jan 26 '08 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,333
hi ...

yes :) ... you shouldn't (and needn't) use eval ... have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. // we have a part of your id
  2. var id = 'optD1S';
  3.  
  4. // now we make the correct id (optD1S1)
  5. var node_id = id + 1;
  6.  
  7. // refer to the node with node_id
  8. var node = document.getElementById(node_id);
  9.  
  10. // setting the disabled attrib to disabled
  11. node.setAttribute('disabled', 'disabled');
  12.  
  13. // remove the attrib
  14. node.removeAttribute('disabled');
  15.  
kind regards
Jan 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.