Results 1 to 3 of 3

Thread: checkboxes with the same name!!!??

  1. #1

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Question checkboxes with the same name!!!??

    hello,

    if i have many checkboxes with the same name but different values,,,like this:
    PHP Code:
    <form method="post" action="order.php">
    <
    input type="checkbox" name="cart" value="123.com">
    <
    input type="checkbox" name="cart" value="123.org">
    <
    input type="checkbox" name="cart" value="123.net">
    <
    input type="checkbox" name="cart" value="123.biz">
    <
    input type="submit" name="b1" value="buy now">
    </
    form
    now when i submit the form, i want to print only the checked items,, note that all of them have the same name,,,please help

    thanx alot...

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    do this:

    PHP Code:
    <form method="post" action="order.php">
    <
    input type="checkbox" name="cart[0]" value="123.com">
    <
    input type="checkbox" name="cart[1]" value="123.org">
    <
    input type="checkbox" name="cart[2]" value="123.net">
    <
    input type="checkbox" name="cart[3]" value="123.biz">
    <
    input type="submit" name="b1" value="buy now">
    </
    form
    Then cycle through them like so:

    PHP Code:
    for ($i=0;$i<4;$i++)
      if (
    $cart[$i] != "")
        print 
    "$cart[$i]<br>\n"
    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3
    scoutt
    Guest
    don't even have to do that. you don't need the numbers in there.
    PHP Code:
    <form method="post" action="order.php">
    <
    input type="checkbox" name="cart[]" value="123.com">
    <
    input type="checkbox" name="cart[]" value="123.org">
    <
    input type="checkbox" name="cart[]" value="123.net">
    <
    input type="checkbox" name="cart[]" value="123.biz">
    <
    input type="submit" name="b1" value="buy now">
    </
    form

Posting Permissions

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



Click Here to Expand Forum to Full Width