Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    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.

  • #2
    New Coder
    Join Date
    Sep 2009
    Posts
    50
    Thanks
    4
    Thanked 4 Times in 4 Posts
    I think we need to know what isn't happening as expected.

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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.

  • Users who have thanked oesxyl for this post:

    jasejunk (12-27-2009)

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •