shadiadiph Posted January 15, 2009 Share Posted January 15, 2009 I know it can be done with anchor tags in html but it looks messy I have some links A-Z clicking 'A' should only display the paragraphs that are started with A like APPLE ANT etc and clicking B BALL BAT etc <td class="two"><a href="<?=???>">A</a></td> <td class="two"><a href="<?=???>">A</a></td> <td class="two"><a href="<?=???>">A</a></td> <p>APPLE</p> <p>ANT</p> <p>BAT</p> <p>BALL</p> Does anyone have any idea how to make this work i can'y think of the work around?? Quote Link to comment Share on other sites More sharing options...
Zephyr_Pure Posted January 15, 2009 Share Posted January 15, 2009 It depends on what you mean by "only display". If you're looking to do that in real time, you'd need to use Javascript. If you're willing to let a page load happen in between, then use a GET var. Is there any PHP code outputting the paragraphs? Where does that paragraph information get pulled from? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted January 15, 2009 Author Share Posted January 15, 2009 wouldn't a page load require javascript too? this why i am asking i am not sure how to do this Quote Link to comment Share on other sites More sharing options...
revraz Posted January 15, 2009 Share Posted January 15, 2009 When he says "page load" he is referring to when the page reloads after you hit a submit button. Quote Link to comment Share on other sites More sharing options...
RestlessThoughts Posted January 15, 2009 Share Posted January 15, 2009 Yes, PHP can reload a page without javascript. And it doesn't have to be with a submit button. It can just be a text link, too. There's several ways to code it. One way is like so: <form method="GET" action="{$_SERVER['PHP_SELF']}"> <a href="{$_SERVER['PHP_SELF']}?variable=A">A</a> <a href="{$_SERVER['PHP_SELF']}?variable=B">B</a> </form> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 you can do this in php or javascript php: <?php function removeAllOther($var,$key,$let) { $letter = $var{0}; if (strtolower($letter) == strtolower($let)) return true; return false; } $array = array("Apple","Ant","Bat","Ball"); $ord = $_GET['ord']; if (strlen($ord) == 1) { // sorry I like to use strlen for variable checks :S sue me array_filter($array,"removeAllOther",$ord); print_r($array); } ?> ^^ for the above make all links look like: http://whatever.com/whatever.php?ord=a or b or c etc javascript code: <script type="text/javascript"> var list; function sortIt(ord) { e = document.getElementById("results"); if (!list.length) { list = e.getElementsByTagName("p"); for (a in list) { list[a] = list[a].innerHTML; } } e.innerHTML = ""; for (i in list) { if (list[i].toUpperCase().substr(0,1) == ord.toUpperCase()) { p = document.createElement("p"); p.appendChild(document.createTextNode(list[i])); e.appendChild(p); } } } </script> <div id="results"> <p>Apple</p> <p>Ant</p> <p>Bat</p> <p>Ball</p> </div> <a href="javascript:sortIt('A');">A</a> <a href="javascript:sortIt('B');">b</a> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.