Jump to content


Photo

running html and php heeeeelp


  • Please log in to reply
13 replies to this topic

#1 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 June 2006 - 04:40 PM

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 04:45 PM

$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:
//checks to see if $_POST['selection'] is empty
if(!empty($_POST['selection'])) {
   $selection = $_POST['selection'];
   //rest of your code here
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 18 June 2006 - 04:48 PM

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
DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 04:50 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
what are those squiggly brackets called?
[/quote]
uh, brackets? lol, now that is quote worthy [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 18 June 2006 - 04:54 PM

() 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.
DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#6 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 June 2006 - 04:56 PM

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?

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


#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 04:58 PM

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]


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 18 June 2006 - 04:59 PM

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
DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 05:06 PM

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:

<?php
   $x = 0;
   if ($x == 0) {
?>
<script lang = 'javascript'>
..
</script>
<?php
  } else {
?>
<script lang = 'javascript'>
.
.
.
</script>
<?php
  }
?>
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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 June 2006 - 05:22 PM

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!

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 05:36 PM

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:

<script lang='javascript'>
  var selection = <?= $_POST['selection'] ?>;
</script>

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 June 2006 - 05:46 PM

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:

     <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>  

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.

    <?php 
          $selection = $_GET['menu_bait_type'];
        echo "my $selection";
?>

Any suggestions on attacking this problem? thanks for the help!

#13 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 05:51 PM

how about changing your input type = 'button' to input type = 'submit'

edit:
also you need </option> after your selection choices
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#14 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 June 2006 - 06:02 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users