Solved

dropdown list

Posted on 2014-03-18
4
201 Views
Last Modified: 2014-03-19
Hi,

I don't know why my Jquery doesn't work :(

I want to show the TicketNumberTxt if the SelectTicketNumber has a value on the onload event.

 if($("#SelectTicketNumber").val() != null || $("#SelectTicketNumber").val() != undefined || $("#SelectTicketNumber").val() != ""){ 
	$("#ShowHideSubTicketText").show();
  }

Open in new window



 
<div class="ShowHideTicketNumber">
 <select name="SelectTicketNumber" id="SelectTicketNumber" style="width:195px;">
<option value=""> </option>
<option value="2">test</option>
<option value="3">next</option>
</select>
</div>

   <div id="ShowHideSubTicketText" class="ShowHideTicketNumber ">
                    <input type="text" class="DisableTicketNumberTxt" id="TicketNumberTxt" name="TicketNumberTxt" />  
                    </div>  

Open in new window

0
Comment
Question by:lulu50
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39937542
I have not used jquery. it could be simply replace by jquery
.submit()

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <script type="text/javascript">
  function test(val)
  {
	   alert(val)
  if(val !=0){ 
	document.getElementById("ShowHideSubTicketText").style.display='block';
  }
  else
	  {
		  	document.getElementById("ShowHideSubTicketText").style.display='block';
	  }
  }

  </script>
 </head>
 <body>
  <div class="ShowHideTicketNumber">
 <select name="SelectTicketNumber" id="SelectTicketNumber" style="width:195px;" onChange="test(this.value)";>
<option value="0"> </option>
<option value="2">test</option>
<option value="3">next</option>
</select>
</div>

   <div id="ShowHideSubTicketText" class="ShowHideTicketNumber " style='display:none'>
                    <input type="text" class="DisableTicketNumberTxt" id="TicketNumberTxt" name="TicketNumberTxt" />  
                    </div>  
                                  
 </body>
</html>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39937547
With jQuery : http://jsfiddle.net/2RdF2/

function updateSubTicketVisibility() {
    var ticketHaveValue = !!$("#SelectTicketNumber").val();
    var cssDisplay = ticketHaveValue ? "block" : "none";
    $("#ShowHideSubTicketText").css("display", cssDisplay);
}

jQuery(function($) {
    $("#SelectTicketNumber").change(updateSubTicketVisibility)
        .trigger("change"); // RUN IT ONCE AT THE << ONLOAD >> EVENT
    
});

Open in new window


CSS :
#ShowHideSubTicketText {
    display:none;
}

Open in new window

0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39937584
its not submit but its $( "#SelectTicketNumber" ).val(); to get value of select option.
0
 

Author Closing Comment

by:lulu50
ID: 39939499
Thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now