0

Good Morning,

I am trying to create a dealer order form for products which occasionally have a sub selection for color available.

It is always limited to 2 colors if there is an option, and the number of items is very limited (max of 8)

What I would like to do is have the primary items/ descriptions available with radio buttons to select a single item only. Then, depending on which item was selected, if it has both color options, give them a secondary radio button to select that. But if only one color is available, then not display anything regarding the color.

I'm assuming that it would take some sort of javascript to accomplish this, but looking for some direction so I'm heading in the right direction from the start.

Thanks,
Douglas

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by showman13
1

I'm assuming php not js.
You'll now from getting the data from the DB if you need 2nd set of radios or not - so build the page there and then - don't use js to create them on the fly.

If you show how your data is structured in the DB, perhaps we can give you some advice, but generally, you could do this:

...in the loop somewhere and concatenating the variable $output with data for html...

if(isset($colour2)) $output .= "<input name='col_$id' type='radio' id="col_$id" value='$colour1' checked="checked" /><label for="col_$id">$colour1</label> <input name='col_$id' type='radio' id="col2_$id" value='$colour2' /><label for="col2_$id">$colour2</label>'; 

Notice that both radios have the same name. Each pair must have a different name to another pair, hence the $id in the name, referring to the id of the product. ID attributes in html must be unique, hence the different col_$id and col2_$id.

0

diafol, Sorry - I just realized that I never responded to this, because I had worked it out and moved on to something else...

Here is what I ended up with:

<?php
        if($tub_ordered==''){
?>
          <tr>
            <td align="center" colspan="4" width="650" bgcolor="#99CCFF"><b>Tubs and Shower Units</b></td>
            <td align="center" colspan="2" width="250">
              <form name="view_cart" action="product_cart.php" method="POST">
                <input type="hidden" name="sub_act" value="view_cart" />
                <input type="image" name="View Cart" src="images/cart_view.png" width="110" height="25" border="0" alt="View Cart">
              </form>
            </td>
          </tr>

          <tr>
            <td width="150">Name</td>
            <td width="300">Description</td>
            <td align="center" valign="middle" width="100">Color</td>
            <td width="100" align="center" valign="middle">Price</td>
            <td align="center" valign="middle" width="100">Qty</td>
            <td align="center" valign="middle" width="150">Select</td>
          </tr>
<?php
          $sql = "
            SELECT rec_id, product_id, product_name, description, color_option, wholesale
            FROM dealer_product
            WHERE prod_type='T'
            AND status='A'
          ";
          $result=mysql_query($sql);
          $prod_ct=1;
          while($product[$prod_ct]=mysql_fetch_array($result)){
?>
            <tr>
            <form name="add_to_cart" action="product_cart.php" method="POST">
              <td><?php print $product[$prod_ct][2]; ?></td>
              <td><?php print $product[$prod_ct][3]; ?></td>
              <td align='center' valign='middle'>
<?php
                if ($product[$prod_ct][4]=='W'){
                  print'WHITE ONLY';
                  print"<input type='hidden' name='color_option' value='W'>";
                }elseif($product[$prod_ct][4]=='C'){
                  // give radio buttons for White or Cream with default to White
?>
                  <input type="radio" name="color_option" value="W" checked="checked"> White<br>
                  <input type="radio" name="color_option" value="C"> Cream
<?php
                }
?>
              </td>
              <td>$<?php print number_format($product[$prod_ct][5], 2); ?></td>
                <input type="hidden" name="prod" value="<?php print $product[$prod_ct][1]; ?>">
                <input type="hidden" name="wholesale" value="<?php print $product[$prod_ct][5]; ?>">
                <input type="hidden" name="prod_type" value='T'>
              <td align="center" valign="middle">
                <input type="hidden" name="qty" value="1">1
              </td>
              <td align="center" valign="middle">
                <input type="hidden" name="sub_act" value="add_item" />
                <input type="image" name="add to cart" src="images/cart_add_to.png" width="110" height="25" border="0" alt="Add to Cart">
              </td>
            </form>
            </tr>
<?php
            ++$prod_ct;
          }
        }else{ // Tub already selected, so display what was selected
?>
          <tr>
            <td align="center" colspan="3" bgcolor="#98FB98"><b>Selected Tub in Cart</b></td>
            <td align="center" colspan="3" bgcolor="#98FB98">
              <?php print $tub_ordered; ?>
            </td>
          </tr>
<?php
        }
?>

It works fine... Thank you for your response.

Douglas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.