PDA

View Full Version : submit button need alert if value not select rather then send to blank page



jonnyfreak
09-27-2012, 09:04 PM
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


<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

bernie1227
09-28-2012, 04:59 AM
Wouldn't it be easier to simply deactivate the button until they have selected a product?

What you could do in answer to your question, is set up a JavaScript to alert onclick if no product is selected using a simple if/else.

jonnyfreak
09-28-2012, 09:43 AM
ideally yes deactivate the button until an option is selected.

how would i go about do that?
thanks

bernie1227
09-28-2012, 09:51 AM
well in order to actually deactivate the button, you should use:


function disable(){
document.getElementById('button').disabled = true;
}

so simply check if one of the products is selected and then trigger the function if it's not.

jonnyfreak
09-28-2012, 10:47 AM
I have tried the following but am sure its wrong


<script type='text/javascript'>
function disable(){
document.getElementById('button').disabled = true;
}
</script>
<form id="button" method="post" action="" onclick="function()">
<p>
<select id="ad_type" name="ad_type">
<option value="" selected="selected">Select premium ad type</option>
<option value="<?php echo TYPE_USER;?>">Featured Agent</option>
</select>

jonnyfreak
09-28-2012, 11:00 AM
thats wrong on my behalf not your. Thanks in advance

jonnyfreak
09-28-2012, 11:12 AM
thinking about it i would need the alert with an if/else statement

bernie1227
09-28-2012, 11:26 AM
you may want something like:


<script type='text/javascript'>
function disable(){
if(ID.value == 'Select Design'){
document.getElementById('button').disabled = true;
}
}
</script>
<form id="button" method="post" action="" onclick="disable()">
<p>
<select id="ad_type" name="ad_type">
<option value="" selected="selected">Select premium ad type</option>
<option value="<?php echo TYPE_USER;?>">Featured Agent</option>
</select>

jonnyfreak
09-28-2012, 11:29 AM
thanks for that, but the process of the form is they select a design (then have to submit that in order to give the values of that design) then choose the size below then send to cart so the alert would be better.

bernie1227
09-28-2012, 11:36 AM
<script type='text/javascript'>
function disable(){
if(ID.value == 'Select Design'){
alert('please select an option');
}
}
</script>
<form id="button" method="post" action="" onclick="disable()">
<p>
<select id="ad_type" name="ad_type">
<option value="" selected="selected">Select premium ad type</option>
<option value="<?php echo TYPE_USER;?>">Featured Agent</option>
</select>

jonnyfreak
09-28-2012, 11:59 AM
ok sorted it to a certain extent

i have used the javascript alert


<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>

onclick="return selection_warn();"


but what if i had another button that actually sent the form to the cart

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

with a size list

<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>
so if this button is selected an alert to say, please select design and size? or if the design has been selected to say please select size?

bernie1227
09-29-2012, 12:47 AM
First you need to set a id to the size selection (for this use the id size), and then create another function:


<script type="text/javascript">
function selection_size_warn() {
if (document.getElementById("selectName").value == 'Select Design' && document.getElementById('Size').value == 'Select Size') {
alert('Please select design and size first');
return false;
} elseif(document.getElementById("selectName").value == 'Select Design'){
alert('Please select design first');
return false;
} elesif(document.getElementById('Size').value == 'Select Size'){
alert('Please select size first');
return false;
} else{
return true;
}
}
</script>