Jump to content

problem with toggle method


jimfog

Recommended Posts

I have a form where it contains a select element(drop down menu) and the aim is that some input fieldsare hidden or displayed upon the user selecting specific items from the drop down menu: Here is the code:

    $("select").change(function(){  if($(this).val() >"0")	 {$('input[name=name],input[name=lastname]').toggle(); }elseif($(this).val() =="0") 	 {$('input[name=name],input[name=lastname]').toggle(); } 

The problem with the above code is that if the user makes a selection again of an item > 0, the elements are hidden. The aim is that whenever the user selects an item > 0 (value of option>0, ) some input elements of the form are displayed and remain displayed. I want these input elements remain hidden only if the user selects option value =0 The problem lies I think with the toggle method, I am not sure if it is the right method for what I want to achieve. I have tried also using this code:

   $("select").change(function(){  if($(this).val() >"0")	 {$('input[name=name],input[name=lastname]').css('display','visible'); }

the above code-despite being OK from a jquery syntax point of view(I tested it with other things)- does not work.I need to stress that the input elements I have targeted I have set inline style=display:none.cause I want them hidden originally and the make them visible upon user selecting option value>0, (as stated above already).

Edited by jimfog
Link to comment
Share on other sites

there is no display:visible property, that was the mistake

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...