HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
form <option value = " "> Bulk Delivery
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form
View previous topic :: View next topic  
Author Message
KANE



Joined: 17 Jan 2005
Posts: 2

PostPosted: Mon Jan 17, 2005 1:48 am     form <option value = " "> Bulk Delivery Reply with quote

Is there a way to set an options value based on javascripting?

I have this set up on one of my webpages -

CENTER><SELECT NAME="product"><option value="">Select one <option value= "5" >5 Gallon Pale
<option value="20">20 Gallon Carboy <option value="55"> 55 Gallon Drum
<option value="100">100 Gal. Tote <option value="250">250 Gal. Tote
<option value = ""> Bulk Delivery </CENTER>

in which product gets calculated based on pricing, etc. I want to know if there is a way for a user to type in a value in another field and be the value for "Bulk Delivery"?

Any help would be appreciated.

-KANE
gavinwm



Joined: 11 Jan 2005
Posts: 27

PostPosted: Mon Jan 17, 2005 3:30 am     Reply with quote

Here's a simple page I did which you can use:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>

<script language="javascript">
<!--
function checkForm() {
if(document.forms[0].product.selectedIndex == 6)
document.forms[0].product.options[6].value = document.forms[0].bulk_value.value;

document.forms[0].bulk_value.value = "";
document.forms[0].submit();
}
//-->
</script>

</head>

<body>
<form onsubmit="javascript:checkForm(); return false;" action="test.php" method="post">
<CENTER>
<SELECT NAME="product">
<option value="">Select one</option>
<option value="5">5 Gallon Pale</option>
<option value="20">20 Gallon Carboy</option>
<option value="55"> 55 Gallon Drum</option>
<option value="100">100 Gal. Tote</option>
<option value="250">250 Gal. Tote</option>
<option> Bulk Delivery</option>
</select>
<br>
<input type="text" name="bulk_value">
<br>
<input type="submit">
</CENTER>
</form>

</body>
</html>

This code will assign Bulk Delivery a value if bulk delivery has been selected and the bulk_value form field has been filled.

The only problem with this code is if someone enters the same number in bulk_value as one of the other option fields. You'll have no way of knowing whether they've chosen Bulk Delivery or not.

You could prevent the user from entering one of your numbers (5, 20, 55, 100, 250) by using some javascript validation, or assign the other options with words and force the user to use a number in the bulk_value field.
gavinwm



Joined: 11 Jan 2005
Posts: 27

PostPosted: Mon Jan 17, 2005 3:36 am     Reply with quote

Duh!

I forgot you should make sure someone enters a value for Bulk Delivery if they've selected that option.

Here's the amended javascript:

<script language="javascript">
<!--
function checkForm() {
if(document.forms[0].product.selectedIndex == 6) {
if(document.forms[0].bulk_value.value == "") {
alert("You must enter a Bulk Delivery value");
return;
}
document.forms[0].product.options[6].value = document.forms[0].bulk_value.value;
}

document.forms[0].bulk_value.value = "";
document.forms[0].submit();
}
//-->
</script>
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial