Home › Forums › JavaScript › I think I need a Javascript solution for radio button’s data
- This topic is empty.
-
AuthorPosts
-
February 21, 2013 at 4:47 pm #42916JamiMember
My issue is the gateway I’m dealing with will only process data for the var ‘installments’ once, so I have to get the user to select from a choice #1 or choice #2 + enter their own number. My problem is with choice #2 –
Using the following:
Total number of payments..
number of payments –
But this returns either installments = ’99’ or
installments = ‘on’ & installments = ‘4’ (or whatever number they choose)I need the var installments to equal either 99 or their entered number. I saw some CSS tricks plus JS that seemed along the lines of what might solve my issue.
When the user selects the #2 radio button is there a way to eliminate it from sending it’s data?
Thank you ~
http://cdpn.io/sxnhEFebruary 21, 2013 at 5:28 pm #125599tomrogers123MemberYou could give the custom option an `id`:
…and then use some conditional logic in your JS:
if( $(‘#other).is(‘:selected’) ) {
// user wants to enter own value
$(‘[name=”installments”]”).not(‘[type=”text”]’).attr(‘name’, ”) // remove all values apart from the entered text.
}
Might I suggest that you also add some UI where the custom textbox only shows if the corresponding choice has been made.
February 21, 2013 at 7:35 pm #125616JamiMemberI do have some UI that hides that input field until selected, but I’m still trying to work out this first.
This is what your solution returns:
installments | Enter Custom..
installments | 2
btnSubmit | Submit
So you see I’m still sending two data values for the var ‘installments’, and only one (numeric) will be accepted all others throw an error.
Is there a way to check if the input field (installments) has data and then disable that second radio button? A disabled form element sends no data I’ve heard. I’d probably have to un-check the first radio, but that would be a small concession if this worked.
Thanks
February 22, 2013 at 3:33 pm #122075JamiMemberIt worked!!!! I’m so thrilled I could scream…. Thank you Thank you.
I have to look into this jQuery, everyone seems to be using it.> “Keep in mind that this will break if javascript is disabled.”
Yes, I am concerned about that. I suppose there is a php way to do this, but I don’t know php. -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.