shibbi3 Posted June 18, 2006 Share Posted June 18, 2006 HelloIm not sure if the follow can be done [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] anyone have any suggestions?? thanks.<?php $selection = empty($_POST['selection']); if ($selection == 'Hard Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','show','Layer2','','hide','Layer3','','hide'); </script> <?php } else if ($selection == 'Saltwater Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','show','Layer3','','hide'); </script> <?php } else if ($selection == 'Swim Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','show'); </script> <?php } else { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','hide'); </script> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/ Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 $selection = empty($_POST['selection']);will not work. empty() is a boolean function that checks to see if something is empty. you would have to do it like so:[code]//checks to see if $_POST['selection'] is emptyif(!empty($_POST['selection'])) { $selection = $_POST['selection']; //rest of your code here}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47014 Share on other sites More sharing options...
deadonarrival Posted June 18, 2006 Share Posted June 18, 2006 A switch may be easier to use... saves some time in all your if-else-else-else's and reduces the number of squiggly brackets you are using.On a slightly different subject: what are those squiggly brackets called?() are parenthesis, what are these called? {}=O Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47016 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]what are those squiggly brackets called?[/quote]uh, brackets? lol, now [i]that[/i] is quote worthy [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47017 Share on other sites More sharing options...
deadonarrival Posted June 18, 2006 Share Posted June 18, 2006 () Parenthesis{} Squiggly things[] Square brackets<> Less than/Greater thanAre all examples of brackets though =( but squiggly brackets doesn't sound right =P they must have a better name. Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47020 Share on other sites More sharing options...
shibbi3 Posted June 18, 2006 Author Share Posted June 18, 2006 lol haha, I have no idea what they're called, one of my teachers called them sexy brackets though :S.Anyways thanks for the help. So I take it I can interweave javascript and php together like that? it doesnt seem to be showing and hiding my layers :(. I've got a form with a jump menu and 3 layers drawn out. I want to show and hide those layers according to the selection :S. There must be an easier way? [code]<form name="form_select_bait" action="products.php" method="post"> <font color="#000000" size="4" face="Copperplate Gothic Bold, Copperplate Gothic Light">Select Bait:</font> <select name="menu1" > <option value="Select Bait" selected>Select Bait</option> <option value="Hard Bait">Hard Bait</option> <option value="Saltwater Bait">Saltwater Bait</option> <option value="Swim Bait">Swim Bait</option> </select> <input name="selection" type="button" value="Go"> </form> <?php $selection = $_POST['selection']; if ($selection == 'Hard Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','show','Layer2','','hide','Layer3','','hide'); </script> <?php } else if ($selection == 'Saltwater Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','show','Layer3','','hide'); </script> <?php } else if ($selection == 'Swim Bait') { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','show'); </script> <?php } else { ?> <script language="JavaScript"> MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','hide'); </script> <?php } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47022 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 Wikipedia calls them curly brackets or braces:[a href=\"http://en.wikipedia.org/wiki/Angle_bracket#Curly_brackets_or_braces_.7B_.7D\" target=\"_blank\"]http://en.wikipedia.org/wiki/Angle_bracket..._braces_.7B_.7D[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47024 Share on other sites More sharing options...
deadonarrival Posted June 18, 2006 Share Posted June 18, 2006 Try a little error checking - make sure that the correct if/else selection is being opened.If that isn't working - your javascript isn't working properly. I'm not great at JS, especially DHTML, so I wouldn't know =PEdit: wikipedia is god. They shall now be known as curly brackets/braces. By order of Wikipedia Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47025 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 you can intermingle php and js but perhaps not in the way that you expect. php will parse it all and send it to the browser. but once the php is parsed, it is parsed, so if you have for instance:[code]<?php $x = 0; if ($x == 0) {?><script lang = 'javascript'>..</script><?php } else {?><script lang = 'javascript'>...</script><?php }?>[/code]only the first <s cript></s cript> will actually be sent to the client, because the php script determined that the condition was true, and therefore ignored the else. So on your client, the 2nd <s cript></s cript> will not exist. Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47028 Share on other sites More sharing options...
shibbi3 Posted June 18, 2006 Author Share Posted June 18, 2006 ahhh I see. For what I want to accomplish, I need to run the function MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','hide');is there a way to run this interweaved with the conditions I set in PHP?Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47031 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 i'm a noob when it comes to js so i don't know if it's possible to grab posted vars in js or not. if so, then it would be better to just grab the posted vars from js and do the whole thing in js. if not, then you would need to pass the posted vars back to js and do your conditions in js instead of php. you would pass your posted var from php to js like so:[code]<script lang='javascript'> var selection = <?= $_POST['selection'] ?>;</script>[/code]the only way you will be able to inter-mingle the two like you are wanting to do is using the AJAX method but i think that would be just overcomplicating things for what you are trying to do...I think..I guess it depends on what you are trying to do overall. Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47032 Share on other sites More sharing options...
shibbi3 Posted June 18, 2006 Author Share Posted June 18, 2006 Thanks for the suggestion!I think I am overcomplicating things.What I want to accomplish is to have a jump menu with the following options:[code] <form name="form_select_bait" action="index.php" method="get"> <select name="menu_bait_type" > <option value="4" selected>Select Bait <option value="1">Hard Bait <option value="2">Saltwater Bait <option value="3">Swim Bait </select> <input type="button" value="Go"> </form> [/code]So depending on the option, I would like to stay on the same page say index.php and display different pictures depending on the selection.Ive tried to check and see if my selection is working and it doesnt seem to be working.[code] <?php $selection = $_GET['menu_bait_type']; echo "my $selection";?>[/code]Any suggestions on attacking this problem? thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47035 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 how about changing your input type = 'button' to input type = 'submit'edit:also you need </option> after your selection choices Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47037 Share on other sites More sharing options...
shibbi3 Posted June 18, 2006 Author Share Posted June 18, 2006 great! that worked.Now that I have the selections I guess ill try to work out a soln :S.Thanks a lot for the help! Quote Link to comment https://forums.phpfreaks.com/topic/12308-running-html-and-php-heeeeelp/#findComment-47038 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.