|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Radio button
Hi all,
I face a problem using radio button. Here is my code: Quote:
i have no problem when there is more than 1 radio button.But, If there is only one radio button, the code cant work well as if i select the radio button, the alert window will come out. There will have no problem if there is more than 1 radio button. Can anyone help me to give your solutions? Regards; :: DuLCiNeA :: |
|
#2
|
|||
|
|||
|
Hey Dulcinea! I don't know if this is the best way to go...but it'll keep you off the hook until someone provides a better solution.
Code:
function blabla(objRadio){
var myValue;
var found = false;
if(objRadio.length == undefinded){ //only one radio button
if(objRadio.checked){
myValue = objRadio.value;
found = true;
}
}
else{ //multiple radio buttons
for (var counter = 0; counter < objRadio.length; counter++ ){
if (objRadio[counter].checked){
myValue = objRadio[counter].value;
found = true;
}
}
}
if (!found){
window.alert('Please select one to delete');
return false;
}
}
This should cover the case when you have only one radio button. I never post anything that I don't test myself, but...considering it's 1:30 AM of a Tuesday (for me), I'll leave it up to you!. Remember to use the code tags, to make the code more readable! And a final piece of advice: try to write functions with parameters (like this one). It will make it posible to reuse the code somewhere else independently of the form and its elements name! Good Luck! ANibal. PS: where are you from? I mean...do you speak spanish (I assume that from your nick)? |
|
#3
|
|||
|
|||
|
Hi Anibal;
Thanks for your code as it works well. if(objRadio.length == undefinded) <<-- It got an error until i realized there was a typo there. It should be undefined. I jus need to do a correction here for those who want to refer Anibal's code. Thanks for your advice. I really appreciate it! p/s: i know nuthing about spanish. I got my nick from reader's digest. Regards; :: DuLCiNeA :: |
|
#4
|
|||
|
|||
|
Hey Dulcinea! Right....undefined! Unfortunatly I didn't see it when I typed it....I would have saved you sometime!!
I'm happy it worked. Good Luck girl! Anibal. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Radio button |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|