Solved

show table row if select menu equals 1

Posted on 2010-11-21
4
404 Views
Last Modified: 2012-08-14
I have previously used the javascript code below to show / hide a table based a check box:

<script language="javascript">
      $("document").ready(function() {
            if (!$("#phone_support").attr('checked')) $(".captionRow").show();
            $("#phone_support").click(function(){
                  if ($("#phone_support").attr('checked')) $(".captionRow").hide();
                  else $(".captionRow").show();
                  })
            });
</script>

How do I change it so the captionRow class only shows if the value of the below select menu is 1?

<select name="ink_brand_id" id="ink_brand_id">
        <?php
do {  
?>
        <option value="<?php echo $row_rs_ink_brand['id']?>"><?php echo $row_rs_ink_brand['ink_brand']?></option>
        <?php
} while ($row_rs_ink_brand = mysql_fetch_assoc($rs_ink_brand));
  $rows = mysql_num_rows($rs_ink_brand);
  if($rows > 0) {
      mysql_data_seek($rs_ink_brand, 0);
        $row_rs_ink_brand = mysql_fetch_assoc($rs_ink_brand);
  }
?>
      </select>
0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 34184139
try:
if( $('#ink_brand_id option:selected').attr('value')==1 )$(".captionRow").show();
0
 

Author Comment

by:petewinter
ID: 34184404
Thanks, but it's not working for me. Can you please check:

<script language="javascript">
      $("document").ready(function() {
                  if( $('#ink_brand_id option:selected').attr('value')==1 )$(".captionRow").show();
            $('#ink_brand_id option:selected').click(function(){
                  if( $('#ink_brand_id option:selected').attr('value')!=1 )$(".captionRow").hide();
                  else $(".captionRow").show();
                  })
            });
</script>
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 34191195
my guess you want to show/hide upon change. If so, try:
<!DOCTYPE html>
<html>
<head>
  <style>
  div { color:red; }
  .captionRow{display:none;}
  </style>
  <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</head>
<body>
  <select name="ink_brand_id" id="ink_brand_id">
    <option value="0">Flowers</option>
    <option value="1" selected="selected">Shrubs</option>
    <option value="2">Trees</option>
    <option value="3">Bushes</option>
    <option value="4">Grass</option>
    <option value="5">Dirt</option>
  </select>
  <div></div>
<script language="javascript">
      $("document").ready(function() {
	 	$('#ink_brand_id').bind('change',function(){
			if( this.selectedIndex > -1  && this.options[this.selectedIndex].value==1)
				$(".captionRow").show();
			else
				$(".captionRow").hide();
		});
		$('#ink_brand_id').change();
      });
</script>
<div class="captionRow">Hi</div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:petewinter
ID: 34200635
Perfect. Many thanks for your help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Press Fixes to Google Speed Test Issues 2 50
Slush on text 2 25
How to open a new browser tab after executing php script 20 44
Pass a js value to an html form 5 42
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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…

739 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