0
votes

I have two radio buttons (Yes/No) and am trying to force it to 'No' when a certain select box selection is made. Here's what I have for the script (below), but it totally disables the radio buttons and doesn't post the data to our db. How can I...

  1. Force the radio button selection to No?
  2. Disable the ability to change the radio button from No to Yes?
  3. Still post the data to our db?

    $(function() {
      $('#presence').change(function() {
        var value = $(this).val()
        var invitation = value === 'common' || value === 'frequent'
             $('.radioyesno input').prop('disabled', invitation)
             if (invitation) {
                  $('.radioyesno input:last').prop('checked', true)
             }
      }).change()
    })
    
1
Please POST HTML part also. Do you have any form or not? how are you trying to POST the data?Anant Kumar Singh

1 Answers

1
votes

Your code seems like it has three problems:

You use $('.radioyn input') and $('.radioyesno input:last'). Is it .radioyn or .radioyesno?

You're calling }).change() for no reason. That call does absolutely nothing. .change() is used to bind an listener to when something changes.

You are not actually posting the update. To post it, you will need to call .submit() on the form, or .click() on the submit button.

Once you fix the above 3 issues, you should achieve your expected behaviour. If anything is not working, I suggest using console.log and breaking your code into smaller areas to test and make sure each line of code does what you expect it to do.