PDA

View Full Version : radio buttons not working properly


codingforumsun
02-24-2009, 08:19 AM
if( cols[5] != 'M' ) {
document.getElementById('Manager').checked=false;
document.getElementById('Trainer').checked=true;
alert("cols[5]: "+cols[5]);
}
else if( cols[5] != 'T' ) {
document.getElementById('Trainer').checked=false;
document.getElementById('Manager').checked=true;
alert("cols[5]: "+cols[5]);

In the above code I get 'M' and 'T' values from databse and the Manager radio Button works fine based on the value 'M'. But never Tariner Radio is checked even the value from database is 'T' and the alert shows it too.

Note: In the form I used attribute name="who" for both the Radio Buttons
Can any one help me? thanks

abduraooft
02-24-2009, 08:33 AM
In the above code I get 'M' and 'T' values from databse and the Manager radio Button works fine based on the value 'M'. But never Tariner Radio is checked even the value from database is 'T' and the alert shows it too. How do you get the value from Database? Are you getting the right values?

codingforumsun
02-24-2009, 02:39 PM
Yes I get either 'M' OR 'T' depending on value in DataBase.
alert("cols[5[] : " cols[5[]); displays it. but somehow the document.getElementBYId('Trainer').checked=true; not working.

codingforumsun.


below is the some more code from webpage. I used name=Who for both the radio buttons.


<input type="radio" value=T name=Who id="Trainer">Trainer?<input type=radio value=M name=Who id="Manager">Manager?

abduraooft
02-24-2009, 02:47 PM
document.getElementById('Manager').checked=false;
document.getElementById('Trainer').checked=true;
I think you need to use the statement having checked=true, since both of them have the same name.
document.getElementById('Trainer').checked=true;

btw, properly enclose the attribute values inside double quotes, to make your markup valid (http://validator.w3.org/#validate_by_input).

codingforumsun
02-24-2009, 04:31 PM
No luck I tried that.

abduraooft
02-24-2009, 04:48 PM
below is the some more code from webpage. I used name=Who for both the radio buttons.
<input type="radio" value=T name=Who id="Trainer">Trainer?<input type=radio value=M name=Who id="Manager">Manager? Could you post your entire form and some more javascript, so that we can try to execute at our end?