Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2009, 07:59 AM   PM User | #1
jasejunk
New Coder

 
Join Date: Dec 2009
Posts: 14
Thanks: 2
Thanked 1 Time in 1 Post
jasejunk is an unknown quantity at this point
Question Problem with HTML Select in PHP

Hello all.
I am working to build my first full site, which happens to be a site for my clothing company.
I have a fairly strong working knowledge of PHP and HTML, and a decent grasp of Javascript.
What I'm trying to do is pass a variable for shirt sizes (contained in a dropdown select box) with PHP.
I have PHP generated pages for all of my shirts, and each contains the same dropdown:

PHP Code:
    echo "<br><br><form action='cart.php?chk=add_to_cart&pid=";
    echo 
$gRow['ID'];
    echo 
"&amp;size=";
    echo 
"<script>document.write(size);</script>";
    echo 
"' method='post' name=\"sizeform\"><select name=\"size\" onChange=\"_chkSize(this)\"><option value='1'>Small</option><option value='2'>Medium</option><option value='3'>Large</option></select>";
    echo 
"<br /><br /><input type='image' name='Add to Cart' alt='Add to Cart' value='Add to Cart' src='/images/add.png'></form>"
This script calls _chkSize(), which is a javascript function, and is supposed to pass the size from the dropdown to the javascript variable "size".

Any advice you can give would be very helpful. I have programmed almost all of this site from scratch with ease, but this part is hanging me up.

I can provide any more information that may be needed, and I understand that this explanation was sub-par, but it was difficult to explain :P

Last edited by jasejunk; 12-27-2009 at 11:52 PM..
jasejunk is offline   Reply With Quote
Old 12-27-2009, 09:04 AM   PM User | #2
FlyingRat
New Coder

 
Join Date: Sep 2009
Posts: 50
Thanks: 4
Thanked 4 Times in 4 Posts
FlyingRat is an unknown quantity at this point
I think we need to know what isn't happening as expected.
FlyingRat is offline   Reply With Quote
Old 12-27-2009, 09:43 AM   PM User | #3
jasejunk
New Coder

 
Join Date: Dec 2009
Posts: 14
Thanks: 2
Thanked 1 Time in 1 Post
jasejunk is an unknown quantity at this point
Can do. The variable simply isn't being set. I believe that the code I have posted above is supposed to perform the function specified each time the dropdown selection is changed, but the variable is set to "" instead.
jasejunk is offline   Reply With Quote
Old 12-27-2009, 04:28 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
try this:
PHP Code:
$url 'cart.php?chk=add_to_cart&pid="' $gRow['ID'] . '"';
echo 
"<br><br>
<form action='"
$url "' method='get' name='sizeform'>
<select name='size'>
<option value='1'>Small</option>
<option value='2'>Medium</option>
<option value='3'>Large</option></select>
<br /><br />
<input type='image' name='Add to Cart' alt='Add to Cart' value='Add to Cart' src='/images/add.png'>
</form>"

I changed method to get and removed size from action url since you don't need it because is already the value of select.

best regards

Last edited by oesxyl; 12-27-2009 at 04:39 PM..
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
jasejunk (12-27-2009)
Old 12-27-2009, 07:57 PM   PM User | #5
jasejunk
New Coder

 
Join Date: Dec 2009
Posts: 14
Thanks: 2
Thanked 1 Time in 1 Post
jasejunk is an unknown quantity at this point
Thanks very much, oesxyl.
I got it to work using a slightly modified version of your code, as the 'get' method was causing some strange reactions for some reason.
I used 'post' instead, and it worked like a charm.
jasejunk is offline   Reply With Quote
Reply

Bookmarks

Tags
cart, javascript, php, variables

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:53 PM.


Advertisement
Log in to turn off these ads.