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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio buttons and textfield script

Status
Not open for further replies.

damipera

Technical User
Dec 1, 2005
134
GB
hi guys, can you give me some ideas as to how i should deal with this?

i have 3 radio buttons (all with the same name and have values 1,2 and 3) and a textfield.

i want to have a javascript that makes the textfield mandatory when radio button 2 OR 3 is selected.

any ideas guys please?

thanks.
 
Add a check into your submit/validation routine


if (radiobutton.value == 2 || radiobutton.value == 3) {
//

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
you will need to check for the checked property too, as the radio button always has a value.

attach an event to the onchange event of each radiobutton and in the function test for which radio is selected and whether its value is 2 or 3; then act accordingly

in jQuery

Code:
$("input[type="radio"]").on('click', function(e){
 if($(this).is(":checked")){
   if($(this).val() == 2 OR $(this).val() == 3 ){
     //make things mandatory
   }
 }
});
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top