Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: help with div's

  1. #1
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default help with div's

    So here is a sample of my code:
    HTML Code:
    <script language='javascript'>
    function changeMenu(id) {
    	if(id == "a") {
    	document.getElementById('a').style.display = "block";
    	document.getElementById('b').style.display = "none";
    	document.getElementById('c').style.display = "none";
    	}
            if(id == "b") {
    	document.getElementById('a').style.display = "none";
    	document.getElementById('b').style.display = "block";
    	document.getElementById('c').style.display = "none";
    	}
            if(id == "c") {
    	document.getElementById('a').style.display = "none";
    	document.getElementById('b').style.display = "none";
    	document.getElementById('c').style.display = "block";
    	}
    }
    </script>
    <a href='javascript:;' onClick="changeMenu('a');">A</a>&nbsp;&nbsp;&nbsp;
    <a href='javascript:;' onClick="changeMenu('b');">B</a>&nbsp;&nbsp;&nbsp;
    <a href='javascript:;' onClick="changeMenu('c');">C</a>&nbsp;&nbsp;&nbsp;
    
    <div id='a' style='display:none;'>this text shows when you click on a</div>
    <div id='b' style='display:none;'>this text shows when you click on a</div>
    <div id='c' style='display:none;'>this text shows when you click on c</div>
    It works....good news.
    Anyway, the problem is, what if I want to link to a certain div.
    For example, the link automatically take it so that it shows the div, without them having to click the A link on the webpage.
    If you don't know what I am asking, please say so, so that I can clear it up.

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't know what your asking...
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    You could always use PHP and a variable in the address (for example '?p=A') and then open that divider (it would be easy to link to - maybe you can't use PHP on your server or website)

    Edit: Despite using PHP, you could also use JavaScript to read a web address and output the query strings to show the divider. Some people have JavaScript disabled in their browser, so you can't really rely on JavaScript that much.

  4. #4
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    I want a link to go to show the div automatically.

    I can use PHP, in fact I do use php on my server. But, how do I make it so that the link the div shows up automatically. If I have to use PHP, please specify how I would code it.

    THANKS!!

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Php:
    Code:
    <script language='javascript'>
    function changeMenu(id) {
    	if(id == "a") {
    	document.getElementById('a').style.display = "block";
    	document.getElementById('b').style.display = "none";
    	document.getElementById('c').style.display = "none";
    	}
            if(id == "b") {
    	document.getElementById('a').style.display = "none";
    	document.getElementById('b').style.display = "block";
    	document.getElementById('c').style.display = "none";
    	}
            if(id == "c") {
    	document.getElementById('a').style.display = "none";
    	document.getElementById('b').style.display = "none";
    	document.getElementById('c').style.display = "block";
    	}
    }
    </script>
    <a href='javascript:;' onClick="changeMenu('a');">A</a>&nbsp;&nbsp;&nbsp;
    <a href='javascript:;' onClick="changeMenu('b');">B</a>&nbsp;&nbsp;&nbsp;
    <a href='javascript:;' onClick="changeMenu('c');">C</a>&nbsp;&nbsp;&nbsp;
    
    <?php
    switch($_GET['disp']){
    case 'A':
    echo "<div id='a' style='display:block;'>this text shows when you click on a</div>"
    ."<div id='b' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='c' style='display:none;'>this text shows when you click on c</div>";
    break;
    case 'B':
    echo "<div id='a' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='b' style='display:block;'>this text shows when you click on a</div>"
    ."<div id='c' style='display:none;'>this text shows when you click on c</div>";
    break;
    case 'C':
    echo "<div id='a' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='b' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='c' style='display:block;'>this text shows when you click on c</div>";
    break;
    default:
    echo "<div id='a' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='b' style='display:none;'>this text shows when you click on a</div>"
    ."<div id='c' style='display:none;'>this text shows when you click on c</div>";
    break;
    }
    ?>
    Then to link:
    Code:
    <a href="page.php?disp=A">Display A</a>
    Jeremy | jfein.net

  6. The Following User Says Thank You to Nile For This Useful Post:

    onestopplay (12-22-2009)

  7. #6
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much!!!!!!!!!

  8. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    It seems like this could be done with a bit less code but I'm not exactley sure how. I'd think using an array with "this" and if the condition is met than the value of "this" is pulled out of the array and set to display. The array is then set to the other values of the array are set to none.

    I don't know how to do this though but would like to see an example if it is possible. Any ideas?

  9. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I've gotten this far...
    Code:
    <script type="text/javascript">
    function getID(theLink) {
    	alert(theLink.id);
    	var div = document.getElementById("getValues");
    	var is_it = div.getElementsByTagName("a");
    	var how_long = is_it.length;
    	var i = 0;
    	while (i < how_long)  {
    		if (theLink.href != is_it[i]) {
    		alert(is_it[i]);
    		}
    		i++;
    	}
    }
    </script>
    	<div id="getValues">
    		<a id="a" href="#this" onclick="javascript:getID(this)">Test</a>
    		<a id="b" href="#that" onclick="javascript:getID(this)">Test</a>
    		<a id="c" href="#then" onclick="javascript:getID(this)">Test</a>
    	</div>
    Need to switch div.getElementsByTagName("a"); though so it gets the ID's rathen than the links anyone know how to do that?

  10. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You need to run through the array, then put the values in a new array.
    Jeremy | jfein.net

  11. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The array has the wrong values though or I'm misunderstanding.

Bookmarks

Posting Permissions

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