Jump to content

Archived

This topic is now archived and is closed to further replies.

shibbi3

running html and php heeeeelp

Recommended Posts

Hello

Im 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
}
?>

Share this post


Link to post
Share on other sites
$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 empty
if(!empty($_POST['selection'])) {
   $selection = $_POST['selection'];
   //rest of your code here
}
[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--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\" /]

Share this post


Link to post
Share on other sites
() Parenthesis
{} Squiggly things
[] Square brackets
<> Less than/Greater than

Are all examples of brackets though =( but squiggly brackets doesn't sound right =P they must have a better name.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 =P

Edit: wikipedia is god. They shall now be known as curly brackets/braces. By order of Wikipedia

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
how about changing your input type = 'button' to input type = 'submit'

edit:
also you need </option> after your selection choices

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.