www.webdeveloper.com
Results 1 to 10 of 10

Thread: Image onClick

  1. #1
    Join Date
    Apr 2008
    Posts
    64

    Image onClick

    I would like to use an onClick on a couple of <img> tags to show/hide additional fields. For example- I have images for "+" and "-" signs. When I click on the "+" image, I want additional fields to display, and when I click the "-" image, I want fields to disappear. If this is possible, what would the code look like? Thanks.

  2. #2
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,931

    Question

    Quote Originally Posted by baldwingrand View Post
    I would like to use an onClick on a couple of <img> tags to show/hide additional fields. For example- I have images for "+" and "-" signs. When I click on the "+" image, I want additional fields to display, and when I click the "-" image, I want fields to disappear. If this is possible, what would the code look like? Thanks.
    Yes, it's possible.
    What code have you attempted so far?

  3. #3
    Join Date
    Apr 2008
    Posts
    64
    Here's what I have so far... I initially used radio buttons, so I've left them in for the example. I would probably also need to be able to disable the "-" image when only one keyword search box is available. Thanks!


    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function toggleSearch() 
    {
    	toggleDisabled(document.getElementById("divSelect"));
    	toggleDisabled(document.getElementById("divSelect2"));
    	toggleDisabled(document.getElementById("cboSelect3"));
    }
    
    function displaySelect()
    {
    	divSelect2.style.display = "none";
    	divMatch2.style.display = "none";
    	divMatch1.style.display = "";
    	
    	valid = false;
    	if(document.frmIssueAdvancedSearch.rbPlusMinus[0].checked)
    		{
    			valid = true;
    			divSelect2.style.display = "";
    			divMatch2.style.display = "";
    			divMatch1.style.display = "none";
    		}
    	if(document.frmIssueAdvancedSearch.rbPlusMinus[1].checked)
    		{
    			valid = true;
    			divSelect2.style.display = "";
    			divMatch2.style.display = "";
    			divMatch1.style.display = "none";
    		}
    }
    
    function toggleDisabled(el) 
    {
    	try 
    	{
    		el.disabled = !el.disabled;
    	}
    
    	catch(E){}
    	if (el.childNodes && el.childNodes.length > 0) 	
    	{
    		for (var i=0; i<el.childNodes.length; i++) 
    		{
    		toggleDisabled(el.childNodes[i]);
    		}
    	}
    }
    
    </script>
    </head>
    
    <body>
    
    <form name="frmIssueAdvancedSearch" id="frmIssueAdvancedSearch" method="post">
    <table width="99%" border="1" class="WebApps">
    	<tr><td colspan="2"><h3>Keyword Search</h3></td></tr>
    	<tr>
    		<td colspan="2">
    		<div id="divMatch1">
    			<p><input name="checkbox" type="checkbox" id="checkbox" value="toggleSearch()" onClick="toggleSearch()" checked>Match the following criteria:</p>
    		</div>
    		
    		<div id="divMatch2" style="display:none;">
    			<p>
    			<input name="checkbox2" type="checkbox" id="checkbox2" value="toggleSearch()" onClick="toggleSearch()" checked>Match 
    			<select name="cboCriteria" id="cboCriteria">
    				<option selected>all</option>
    				<option>any</option>
    			</select>of the following criteria:
    			</p>
    		</div>
    		
    		<div id="divSelect" style="padding:3 pt;">
    			<p>
    			<select name="cboSelect" id="cboSelect">
    				<option>Title</option>
    				<option>Description</option>
    				<option>Issue Type</option>
    				<option>Function</option>
    			</select>&nbsp;&nbsp;contains &nbsp;&nbsp;
    			
    			<input name="txtKeyword" type="text" id="txtKeyword" size="30" maxlength="30">
    			<img src="../images/plus.gif" width="15" height="15" alt=""> 
    			<img src="../images/minus.gif" width="15" height="15" alt="">
    			<input type="radio" name="rbPlusMinus" id="rbPlusMinus" value="0" onClick="displaySelect()">+
    			<input type="radio" name="rbPlusMinus" id="rbPlusMinus" value="1" onClick="displaySelect()">-
    			</p>
    		</div>
    		
    		<div id="divSelect2" style="padding:3 pt; display:none;">
    			<p>
    			<select name="cboSelect2" id="cboSelect2">
    				<option>Title</option>
    				<option>Description</option>
    				<option>Issue Type</option>
    				<option>Function</option>
    			</select>&nbsp;&nbsp;contains &nbsp;&nbsp;
    			
    			<input name="textfield" type="text" id="textfield" size="30" maxlength="30">
    			</p>
    		</div>
    		
    		<div id="divOpenDate" style="padding:3 pt;">
    			<h4>&nbsp;</h4>
    			<h4>When opened:</h4>
    			<p>
    			<select name="cboOpenDate" id="cboOpenDate">
    				<option selected>15 days ago</option>
    				<option>one month ago</option>
    				<option>three months ago</option>
    			</select>
    			</p>
    		</div>
    			<p>&nbsp;</p>
    			<p>
    			<input name="button" type="submit" class="button" id="button2" value="Search">
    			<input name="Reset" type="reset" class="button" id="button" onClick="parent.location='ip_issues_search.asp'" value="Reset Search">
    			</p>
    		</td>
    	</tr>
    </table>
    <p>&nbsp;</p>
    </form>
    
    </body>
    </html>
    			

  4. #4
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,931

    Lightbulb Try this ...

    Substitute your images for the <button> tags
    and place your code between the <div> tags that will do what you want when the "+" is pressed.
    Code:
    <html>
    <head>
    <title>Show Hide  DIV</title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?p=993689#post993689
    
    function Show(IDS,flag) {
      document.getElementById(IDS).style.display = flag;
    }
    </script>
    </head>
    <body>
    <button onclick="Show('divTag','block')">+</button>
    <button onclick="Show('divTag','none')">-</button>
    <div id="divTag" style="display:none">
    Information to display with plus sign pressed
    </div>
    </body>
    </html>

  5. #5
    Join Date
    Apr 2008
    Posts
    64
    This works very well- but, I have more than one <div> tag I need to show/hide- the "divMatch1" and "divMatch2" - is there a function that will allow for passing more than one div in at a time?

  6. #6
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,931
    Sure.

    What do your script tag IDs look like?
    How many IDs at a time?

  7. #7
    Join Date
    Apr 2008
    Posts
    64
    Well, there are 4, but not sure if I need to reference them all. The general idea is:

    if you select "+":

    divSelect1 - 'block'
    divSelect2 - 'block'
    divMatch2 - 'block'
    divMatch1 - 'none'

    if you select "-":

    divMatch1 - 'block'
    divSelect1 - 'block'
    divSelect2 - 'none'
    divMatch2 - 'none'

  8. #8
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,931

    Wink Try this ...

    Will this work for you?
    Code:
    <html>
    <head>
    <title>Show Hide  DIV</title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?p=993689#post993689
    
    var divOrder = ['divSelect1','divSelect2','divMatch1','divMatch2'];
    
    function Show(info) {
      var temp = info.split(',');
      for (var i=0; i<temp.length; i++) {
        IDS = divOrder[i];  // alert(i+' : '+IDS);
        if (temp[i] == 0) {
          document.getElementById(IDS).style.display = 'none';
        } else {
          document.getElementById(IDS).style.display = 'block';
        }
      }
    }
    </script>
    </head>
    <body onLoad="Show('0,0,0,0')">
    <button onclick="Show('1,1,0,1')">+</button>
    <button onclick="Show('1,0,1,0')">-</button>
    <div id="divSelect1" style="display:none">divSelect1</div>
    <div id="divSelect2" style="display:none">divSelect2</div>
    <div id="divMatch1" style="display:none">divMatch1</div>
    <div id="divMatch2" style="display:none">divMatch2</div>
    </body>
    </html>
    Could add a check to assure length of 'info' passed to "Show(info)" function was the same length as the divOrder array. I'll leave that as an exercise for the student.

  9. #9
    Join Date
    Apr 2008
    Posts
    64

    resolved

    This works beautifully. Thank you so much for all your help!

  10. #10
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,931
    You're most welcome.
    Glad I was able to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.54890 seconds
  • Memory Usage 2,955KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates