Link to home
Start Free TrialLog in
Avatar of smares32371

asked on

javascript IF on radio button value

I have a radio group, bill 3 radio buttons

I could ge the radio button value.

On the c value i want to do a javascript if() to validate the credit card fields only if radio button with the c value is selected
Avatar of leakim971
Flag of Guadeloupe image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@smares32371: not sure if you need this advice, but i would suggest that you go for a drop-down rather than radio buttons for this one. In this way, all you need to do is, check the value of one field.

Let me know if you code base for this.
Please no points for this comment of mine, since if @leak's reply works, he deserve all points :)
Avatar of smares32371


leakim971: ok its working how do i validate the rest of the credit card fields, there is like 10 more
I just want to make sure that the credit card fields are filled in .
line 21 :
return field.value.length>0;

Open in new window

we check the field have one char (>0)
if you want 10 charactere or more :
return field.value.length>=10;

Open in new window

I meant I want 2 other fields to give alerts if they not filled in
close the question, award points (or not), try to understand the code, create a new question if you encounter difficulties
i do understand the code but it only allows you to validate one field if the third radio button is selected lets forget about credit card fields, in general how would i validate normal fields base on the third button when there is more than one field.
what do you mean by validate ? Not empty ? Check the length propertie of its value (a string)

var myField_Value = document.getElementById( myField_ID ).value;
var myField_Is_Filled = myField_Value.length > 0; // this return true or false

with a field like this one :

<input type="text" id="myField_ID" name="myField_Name" />

Open in new window

to validate multiple fields : return myField1_Is_Filled && myField2_Is_Filled && myField3_Is_Filled;
yes not empty