Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dropdown list

Posted on 2014-03-18
4
Medium Priority
?
216 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

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