submit button need alert if value not select rather then sen

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

submit button need alert if value not select rather then sen

Post 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
Last edited by Benjamin on Thu Sep 27, 2012 3:23 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
TildeHash
Forum Commoner
Posts: 43
Joined: Fri Jul 16, 2010 7:17 am
Location: Apple Valley, California

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

Post 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();"
Last edited by TildeHash on Sat Sep 29, 2012 2:06 am, edited 1 time in total.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post by jonnyfortis »

this is giving me an alert on alert('Please select design first';

i do have other javascript on the page
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post by jonnyfortis »

its ok it was missing a ) close bracket
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post by jonnyfortis »

work perfect, thanks for your time
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post 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
User avatar
TildeHash
Forum Commoner
Posts: 43
Joined: Fri Jul 16, 2010 7:17 am
Location: Apple Valley, California

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

Post 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]
Post Reply