The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript I think I need a Javascript solution for radio button’s data

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #42916

    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 ~


    You 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.


    I 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.



    It 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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.