Solved

dropdown list

Posted on 2014-03-18
4
203 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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…

810 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