Select box value changes value of hidden field

D

dvwool

Hello,

Another newbie here... I've been trying to make this work for days now
and have finally decided to post as I can't seem to get it to work.
Here's what I'm trying to do...

I have a select box with three options and a separate hidden field.
The value of a hidden field is dependent upon which of the three
options is selected. For example, the three select options are 1, 2,
3... if 1 is selected, the value of the hidden field is 9.99, if 2 is
selected the value of the hidden field is 12.99, if 3 is selected, the
value of the hidden field is 15.99.

Thanks in advance for your help!
-Dave
 
P

petermichaux

Hello,

Another newbie here... I've been trying to make this work for days now
and have finally decided to post as I can't seem to get it to work.
Here's what I'm trying to do...

I have a select box with three options and a separate hidden field.
The value of a hidden field is dependent upon which of the three
options is selected. For example, the three select options are 1, 2,
3... if 1 is selected, the value of the hidden field is 9.99, if 2 is
selected the value of the hidden field is 12.99, if 3 is selected, the
value of the hidden field is 15.99.

Thanks in advance for your help!
-Dave

What happens to this data when the form is submitted? They are entered
into a database?

These look like prices. You don't really want the customer submitting
their own prices. I could make a form that submits any price I want
based on this type of setup. Hidden isn't really hidden. If you use
"View Source" in your browser you can see it. Unless you are doing some
server-side processing you may sell option 2 to me for $0.01. You
probably want to submit only the 1, 2, or 3 and then on the server-side
match the selection with the price.

Peter
 
D

dvwool

The form submits to a database on an e-commerce host.

Thanks for the heads up on the possibility of someone posting
fraudulant prices... I was aware of that hole and will be addressing
that.

Any input on how to do what I'm trying to with javascript?

Thanks!
 
L

Lee

(e-mail address removed) said:
The form submits to a database on an e-commerce host.

Thanks for the heads up on the possibility of someone posting
fraudulant prices... I was aware of that hole and will be addressing
that.

Any input on how to do what I'm trying to with javascript?

Setting the values of the hidden fields is trivial, but now
that you are aware of the security hole, you don't really
still want to do that, do you?


--
 
D

dvwool

No... probably won't do it that way... but I'm interested in seeing the
working code now since I spent so much time on it...
 
R

RobG

(e-mail address removed) said on 26/04/2006 1:42 PM AEST:
No... probably won't do it that way... but I'm interested in seeing the
working code now since I spent so much time on it...

Change the type of the input to hidden:

<script type="text/javascript">

function update(sel, tgt)
{
tgt.value = sel.options[sel.selectedIndex].value;
}

</script>

<form action=""><div>
<input type="text" name="t01">
<select name="s01" onchange="update(this, this.form.t01)">
<option value="">Select an option
<option value="9.99">1
<option value="12.99">2
<option value="15.99">3
</select>
</div></form>
 
D

dvwool

Thanks so much for the response Rob!

That is almost what I'm going for... what if I wanted to populate "t01"
with values that are different from the values in "s01". For example,
when option 1 is selected with a value of 9.99, t01 gets a value of
3.50... when option 2 is selected with value of 12.99, t01 gets a value
of 4.00... and when option 3 is selected, t01 gets a value of 4.50.
Possible?

Thanks again for your help... if it takes too much effort don't worry
about it.

-Dave



(e-mail address removed) said on 26/04/2006 1:42 PM AEST:
No... probably won't do it that way... but I'm interested in seeing the
working code now since I spent so much time on it...

Change the type of the input to hidden:

<script type="text/javascript">

function update(sel, tgt)
{
tgt.value = sel.options[sel.selectedIndex].value;
}

</script>

<form action=""><div>
<input type="text" name="t01">
<select name="s01" onchange="update(this, this.form.t01)">
<option value="">Select an option
<option value="9.99">1
<option value="12.99">2
<option value="15.99">3
</select>
</div></form>
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top