Getting value from Drop down menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimmyg123
    New Member
    • Mar 2007
    • 21

    Getting value from Drop down menu

    Hi,
    I have used a loop so there are a number of quantity drop down menu's designed for a shopping cart style website, with $i being the loop counter and qty being the name of the drop down menu so I have used (ignore the onChange function)

    Code:
    <select id='qty{$i}' onChange='findTotal($price,$i)'>
    	<option value='0'>0</option>
    	<option value='1'>1</option>
    	<option value='2'>2</option>
    	<option value='3'>3</option>
    	<option value='4'>4</option>
    	<option value='5'>5</option>
    	<option value='6'>6</option>
    </select>
    What I need to know is how to get the value of the selected option when a link is clicked, my link is currently

    Code:
    <a href="index.php?quantity=$qty{$i}>Add to Cart</a>
    however I know this does not work, when I check the link on the live page it's linking to



    and so on for each link...

    Can anyone help me find a way to have the value of the quantity in place of the number of the loop?
    Thanks in advance!
  • jimmyg123
    New Member
    • Mar 2007
    • 21

    #2
    Anyone????

    Comment

    • merseyside
      New Member
      • Mar 2007
      • 48

      #3
      Originally posted by jimmyg123
      Hi,
      I have used a loop so there are a number of quantity drop down menu's designed for a shopping cart style website, with $i being the loop counter and qty being the name of the drop down menu so I have used (ignore the onChange function)

      Code:
      <select id='qty{$i}' onChange='findTotal($price,$i)'>
      	<option value='0'>0</option>
      	<option value='1'>1</option>
      	<option value='2'>2</option>
      	<option value='3'>3</option>
      	<option value='4'>4</option>
      	<option value='5'>5</option>
      	<option value='6'>6</option>
      </select>
      What I need to know is how to get the value of the selected option when a link is clicked, my link is currently

      Code:
      <a href="index.php?quantity=$qty{$i}>Add to Cart</a>
      however I know this does not work, when I check the link on the live page it's linking to



      and so on for each link...

      Can anyone help me find a way to have the value of the quantity in place of the number of the loop?
      Thanks in advance!
      I'm assuming that you want the following behaviour? User clicks on link to a paage which contains the select list. Depending on the value of quantity in the query string, the page is to load with that value in the select list pre-selected?

      Try something like this:

      [PHP]
      $opts = array(0,1,2,3,4 ,5,6);

      print "<select id=\"qty$i\" onChange=\"find Total($price,$i )\">";
      for ( $j = 0, $j < count($opts); $j++ )
      {
      print "<option value=\"".$opts[$j]."\"";
      print ($quantity == $opts[$j] ? " selected " : "");
      print ">$opts[$j]</option>";
      }
      print "</select>"
      [/PHP]

      Comment

      Working...