drop down menu returning 0 value

M

MickG

Hi,

I want my drop down box to be able to return wrap =0. It works fine
with 2.95 and 3.95 but does bot return a 0. Could anyone help?


<select name="bookwrapping"
onchange="if(this.selectedIndex)wrap=+(this[this.selectedIndex].value);">
<option value ="0">none</option>
<option value="2.95">Standard Wrapping</option>
<option value="3.95">Deluxe Wrapping</option>
 
M

McKirahan

MickG said:
Hi,

I want my drop down box to be able to return wrap =0. It works fine
with 2.95 and 3.95 but does bot return a 0. Could anyone help?


<select name="bookwrapping"
onchange="if(this.selectedIndex)wrap=+(this[this.selectedIndex].value);">
<option value ="0">none</option>
<option value="2.95">Standard Wrapping</option>
<option value="3.95">Deluxe Wrapping</option>

What happens if you remove:
"if (that.selectedIndex) "
 
M

McKirahan

if, i choose none then it says that wrap is undefined.

You've haven't posted enough of your code for us to know what you're really
doing.

Is it anything like the following? Watch for word-wrap.

<html>
<head>
<title>wrap.htm</title>
<script type="text/javascript">
function wraps(that) {
var wrap = that.options[that.selectedIndex].value;
alert(wrap);
}
</script>
</head>
<body>
<form>
<select name="bookwrapping" onchange="wraps(this)">
<option value ="0" selected>none</option>
<option value="2.95">Standard Wrapping</option>
<option value="3.95">Deluxe Wrapping</option>
</form>
</body>
</html>
 
M

Michael Winter

(e-mail address removed) wrote:

Please quote what you're responding to when replying to a post.
if, i choose none then it says that wrap is undefined.

You can't choose 'None', at least not initially. The change event only
fires when the value changes. As the first option is already
selected[1], no change will occur. You have two options: place a dummy
value in the SELECT element and have it selected by default, or
initialise the wrap variable to zero (0) when you declare it. I'd
probably go for the latter.

Mike


[1] You should always specify an initial option by including the
selected attribute in the opening tag of an OPTION element.
Do not rely the first option being selected by default.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top