Page 1 of 1

submit button need alert if value not select rather then sen

Posted: Thu Sep 27, 2012 2:49 pm
by jonnyfortis
I have a product page that sends to a product detail page, The detail page also has all other products from the catagory.. The problem is when they land on the page it shows their selected product but in order for the information to pass to the cart they need to select the product first, even though they are already on the page (because there are other produts there) at present if they do not choose their product and just hit select it sends them to a blank page. i need to to prompt and say " please select design first)

this is the form

Code: Select all

<form id="FormName" action="" method="get" name="FormName">
            <table>
              <tr valign="middle">
                <td width="30" height="40" class="meduimTXT">1.</td>
                <td width="190" align="left"><div align="left">
                  <select name="ID" class="text" id="selectName">
                    <option value="Select Design">Select Design</option>
                    <?php
                                        mysql_select_db($database_beau, $beau);
                                        $query = sprintf("SELECT * FROM beauProd WHERE CatID = '%s'", GetSQLValueString($row_Recordset1['CatID'], "int"));
                                        $results = mysql_query($query, $beau) or die(mysql_error());
                                        $productsInCategory = array();
                                        while($row = mysql_fetch_array($results)){
                                                  $productsInCategory[] = $row['ID'];
                                                  ?>
                    <option value="<?php echo $row['ID']; ?>"><?php echo $row['name']; ?></option>
                    <?php
                                        }
                                        ?>
                  </select>
                </div></td>
                <td width="190" align="left"><input type="image" src="../images/select design.gif" border="0" name="button" id="button" value="select new design" /></td>
              </tr>
            </table>
          </form>



thanks in advance

Re: submit button need alert if value not select rather then

Posted: Fri Sep 28, 2012 3:52 am
by TildeHash
jonnyfortis wrote:I have a product page that sends to a product detail page, The detail page also has all other products from the catagory.. The problem is when they land on the page it shows their selected product but in order for the information to pass to the cart they need to select the product first, even though they are already on the page (because there are other produts there) at present if they do not choose their product and just hit select it sends them to a blank page. i need to to prompt and say " please select design first)

this is the form

Code: Select all

<form id="FormName" action="" method="get" name="FormName">
            <table>
              <tr valign="middle">
                <td width="30" height="40" class="meduimTXT">1.</td>
                <td width="190" align="left"><div align="left">
                  <select name="ID" class="text" id="selectName">
                    <option value="Select Design">Select Design</option>
                    <?php
                                        mysql_select_db($database_beau, $beau);
                                        $query = sprintf("SELECT * FROM beauProd WHERE CatID = '%s'", GetSQLValueString($row_Recordset1['CatID'], "int"));
                                        $results = mysql_query($query, $beau) or die(mysql_error());
                                        $productsInCategory = array();
                                        while($row = mysql_fetch_array($results)){
                                                  $productsInCategory[] = $row['ID'];
                                                  ?>
                    <option value="<?php echo $row['ID']; ?>"><?php echo $row['name']; ?></option>
                    <?php
                                        }
                                        ?>
                  </select>
                </div></td>
                <td width="190" align="left"><input type="image" src="../images/select design.gif" border="0" name="button" id="button" value="select new design" /></td>
              </tr>
            </table>
          </form>



thanks in advance
This is done with JavaScript, not PHP.

Place this in your page(s') header:

Code: Select all

<script type="text/javascript">
	function selection_warn() {
		if (document.getElementById("selectName").value == 'Select Design') {
			alert('Please select design first');
			return false;
		} else {
			return true;
		}
	}
</script>
And this on the submit button:

Code: Select all

onclick="return selection_warn();"

Re: submit button need alert if value not select rather then

Posted: Fri Sep 28, 2012 6:43 am
by jonnyfortis
this is giving me an alert on alert('Please select design first';

i do have other javascript on the page

Re: submit button need alert if value not select rather then

Posted: Fri Sep 28, 2012 6:46 am
by jonnyfortis
its ok it was missing a ) close bracket

Re: submit button need alert if value not select rather then

Posted: Fri Sep 28, 2012 6:48 am
by jonnyfortis
work perfect, thanks for your time

Re: submit button need alert if value not select rather then

Posted: Fri Sep 28, 2012 7:03 am
by jonnyfortis
i have got another question

thus works great but in the form there are two select lists. the first is working and the button is correct.

but the second select list shows the sizes and the next button send the data to the shopping cart

<select name="os0" class="text">
<option value="Select Size">Select Size</option>
<option value="<?php echo $row2['Size']; ?>"><?php echo $row2['Size']; ?></option>
<?php
}

?>
</select>

<input type="image" src="images/add.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online." />

so if the user just tries to add to cart they get another alert saying you need to select the design and size. or you need to select the size if they have selected the design


thanks in advance

Re: submit button need alert if value not select rather then

Posted: Sat Sep 29, 2012 2:26 am
by TildeHash
jonnyfortis wrote:its ok it was missing a ) close bracket
Sorry about that.
jonnyfortis wrote:i have got another question

thus works great but in the form there are two select lists. the first is working and the button is correct.

but the second select list shows the sizes and the next button send the data to the shopping cart

<select name="os0" class="text">
<option value="Select Size">Select Size</option>
<option value="<?php echo $row2['Size']; ?>"><?php echo $row2['Size']; ?></option>
<?php
}

?>
</select>

<input type="image" src="images/add.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online." />

so if the user just tries to add to cart they get another alert saying you need to select the design and size. or you need to select the size if they have selected the design


thanks in advance
Like this, perhaps?

Code: Select all

<script type="text/javascript">
        function selection_warn() {
                if (document.getElementById("selectName").value == 'Select Design' && document.getElementById("selectSize").value == 'Select Size') {
                        alert('Please select design and size');
                        return false;
                } else {
                        if (document.getElementById("selectName").value == 'Select Design') {
                                alert('Please select design first');
                                return false;
                        } else {
                                if (document.getElementById("selectSize").value == 'Select Size') {
                                        alert('Please select size');
                                        return false;
                                } else {
                                        return true;
                                }
                        }
                }
        }
</script>
Add this to the "os0" select tag:
[text]id="selectSize"[/text]