Solved

Hide/show - view checkboxes to <a> links

Posted on 2011-09-08
10
230 Views
Last Modified: 2012-05-12
Hey,

I have a Google Map section on my site with 3 categories:

- Alpine
- Nordic
- Tubing

Right now they all have say 10 markers for each category. And are currently can be hide/show via a checkbox. I am looking to move it to something like:

 
<div class="marker_legend">
	<ul>	
		<li><a href="#alpine"><span><img width="12" height="20" style="margin-bottom:-6px;" alt="" src="http://localhost:8888/ski/wp-content/themes/images/googlepins/blue_Marker.png"> Alpine</span></a></li>
		<li><a href="#nordic"><span><img width="12" height="20" style="margin-bottom:-6px;" alt="" src="http://localhost:8888/ski/wp-content/themes/images/googlepins/red_Marker.png"> Nordic</span></a></li>
		<li><a href="#tubing"><span><img width="12" height="20" style="margin-bottom:-6px;" alt="" src="http://localhost:8888/ski/wp-content/themes/images/googlepins/green_Marker.png"> Tubing</span></a></li>
		
	</ul>
</div>

Open in new window


Another developer coded this section for the checkboxes:

 
function hideOrShowPins(whoToShow,whichBox){
	
	for (i=0;i<markers.length;i++ ){
			if(markers[i][1]==whoToShow  && whichBox.checked == false){
				markers[i][0].hide();
			}else if(markers[i][1]==whoToShow){
				markers[i][0].show();
			}
		}

}

Open in new window


And lastly, the output of the checkboxs looks something like:

<input type="checkbox" onclick="hideOrShowPins('alpine',this);" checked="checked" value="alp" name="al">

Open in new window


What would be the best way do this using <a> not the checkboxes?

Thanks!

Ryan
0
Comment
  • 6
  • 4
10 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36503813
Simply this? (if the javascript was working already :) )
<a href="javascript:hideOrShowPins('alpine',this);" name="al" id="al">Toggle</a>
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36503828
I tried that, thought it would be that simple :)

The code is checking for checked true/false. Guessing that is why its not firing?

    	function hideOrShowPins(whoToShow,whichBox){
    		
			for (i=0;i<markers.length;i++ ){
 				if(markers[i][1]==whoToShow  && whichBox.checked == false){
 					markers[i][0].hide();
 				}else if(markers[i][1]==whoToShow){
 					markers[i][0].show();
 				}
 			}
    	
    	}

Open in new window

0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36503867
rather than checking for check/uncheck....look for the caption of the anchor
update it to

function hideOrShowPins(whoToShow,whichBox)
{    		
	for (i=0;i<markers.length;i++ )
        {
 		if(markers[i][1]==whoToShow  && whichBox.html() == "hide")
                {
                         whichBox.html("show") ;
 		         markers[i][0].hide();
 		}
               else if(markers[i][1]==whoToShow)
                {
                         whichBox.html("hide") ;
 			markers[i][0].show();
 		}
 	}	
}

<a href="javascript:hideOrShowPins('alpine',this);" name="al" id="al">show</a>

Open in new window

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36503907
Hey, no go on that. The only limitation is the output of that is from the google map API. A marker looks like:

<img style="width: 20px; height: 34px; -moz-user-select: none; border: 0px none; padding: 0px; margin: 0px; position: absolute; left: 295px; top: 220px; z-index: -144372608; cursor: pointer;" src="http://localhost:8888/ski/wp-content/themes/ski-maine/images/googlepins/blue_MarkerA.png" id="mtgt_unnamed_0">

Open in new window


I also tried that code on a onclick event
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36503930
Here is an example of how it works now: http://goo.gl/srIOP - at the bottom right are the checkboxes. That same behavior but im trying to get the toggle on the link instead.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36504038
i have only changed the if condition, it should not matter where the marker output is coming from.
What is the output of my code
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36504050
This is what I have for my <a>

					<li><a href="javascript:hideOrShowPins('alpine',this);" id="al" name="al"><span><img src="<?php bloginfo( 'template_url' ); ?>/images/googlepins/blue_Marker.png" alt="" width="12" height="20" style="margin-bottom:-6px;"/> Alpine</span></a></li>

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36504102
Not sure how above code matters.

In that hideOrShowPins(), where is the marker array taken from? what are its values?
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36506443
Looking through it again, I think i would be better usability wise and code to attach it to the code you worked on before: http://jsfiddle.net/nhDxH/7/

So say you click Alpine (in the accordion) you would see ONLY the Alpine markers. If you click the Nordic header in the accordion you'll only see the Nordic markers.

The checkbox code to fire that function posted in my question at the top looks like:

<div id="toggle_markers">
	<div class="alp">
		<input name="al" type="checkbox" value="alp" checked="checked" onclick="hideOrShowPins('alpine',this);"/>&nbsp; Alpine
	</div>
	<div class="alp">
		<input name="no" type="checkbox" value="no" checked="checked" onclick="hideOrShowPins('nordic',this);" />
		&nbsp; Nordic
	</div>
	<div class="alp">
		<input name="tu" type="checkbox" value="tu" checked="checked" onclick="hideOrShowPins('tubing',this);" />
		&nbsp; Tubing
	</div>
</div>

Open in new window

0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 36506447
That said we can find out HOW it is getting ALL alpine markers and $(XXX).hide(); to hide them all.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript comparing two dates 3 19
Show tab when enter div and change underline color 3 35
key press alert 2 18
how can i get 4 nd 5 ? 3 12
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

778 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