0

I am using the following coding in a website I am building but rather than the text input field showing if one option is selected, I need it show if the user selects other options as well?

for example oit currently shows the text input field if the user selects option 2 from the select menu but need to show as well if the user selects option 4 in the select menu, below is my jfiddle code so far

it currently shows the extra text input fields when Domestic+ is selected in the select menu but need the text input fields to show as well when Commercial is selected within the dropdown menu

I found something similar on stackoverflow, see link below

<http://stackoverflow.com/questions/21007591/using-jquery-to-hide-form-elements-based-on-selected-dropdown-option/33055467#33055467>

<http://jsfiddle.net/gxxkdz2m/2/>

Thank you in advance

Ian

3
  • Welcome to stack overflow :) Commented Oct 10, 2015 at 15:50
  • Your jsfiddle code was broken so I fixed it. Please update your link to jsfiddle.net/www139/gxxkdz2m/3 Commented Oct 10, 2015 at 15:52
  • You forgot to add your code to the question, please do so. Commented Oct 10, 2015 at 15:57

2 Answers 2

-1

Is this what you mean? I added comments explaining the code where I changed it.

$(document).ready(function () {
  $('#support select[name="support_plans"]').change(function () {
    // get selected plan value
    var plan = $('#support select[name="support_plans"] option:selected').val();
    // check whether 'Domestic+' or 'Commercial+' is selected
    if (plan == 'Domestic+' || plan =='Commercial+') {
          $('#extra').show();
      } else {
          $('#extra').hide();
      }
  });
});

Fiddle of my Version (updated your fiddle).

http://jsfiddle.net/gxxkdz2m/4/

Sign up to request clarification or add additional context in comments.

2 Comments

And how does that code work? How does it solve the problem?
I don't know if it solves the problem, that's why i asked. Added comments where I changed the original code to explain the changes.
-2

use this javascript code:

$(document).ready(function () {
  $('#support select[name="support_plans"]').change(function () {
    if ($('#support select[name="support_plans"] option:selected').val() == 'Domestic+') {
        $('#extra').css('display', 'inline');
    } else {
        $('#extra').css('display', 'none');
    }
  });

});

1 Comment

Explain that "JavaScript code" that way the op and others in future might learn something about how and why your answer works, and what problems it fixes in the original code, whatever that might be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.