writing from hidden field to text field repost

R

Roy Adams

Hi I'm reposting this question because for some reason can't post
follow up question to this thread.
What I'm trying to do is put the value and text from a a select in to
a text field and to a hidden field respectfully and the value from
dynamically created hidden fiields in to a text fieldin to a text
field all at the same time
Here's the code as viewed through the browser
<body bgcolor="#FFFFFF" text="#000000" >

<SCRIPT LANGUAGE=JavaScript>
<!--
function ch_price (theForm) {
// this changes the price in the price text field
for (i=0; i < 2; i++){
document.form1.oldprice.value = document.form1.prevprice.value;//
the hidden fields
document.form1.price.value =
document.form1.size.options[document.form1.size.selectedIndex].value;
document.form1.Tsize.value =
document.form1.size.options[document.form1.size.selectedIndex].text;

}
}
//-->

</SCRIPT>


<form name="form1" method="post" action="" >
<select name="size" id="size" onChange="ch_price(form1)">
<option selected value="189.00">Select
Size/Colour</option>


<option value="179.00" >95x75cm; 37x29"</option>
<option value=" 89.00" >95x75cm; 37x29"</option>


</select>
<br>
<br>

<input type="hidden" name="prevprice" value="99.00">//hidden fields
that holds value for the oldprice txt field
<input type="hidden" name="prevprice" value="189.00">

<input name="oldprice" class="price" type="text" id="oldprice"
readonly = true value="189.00" size="5" >
<input name="price" class="price" type="text" id="price" readonly =
true value="179.00" size="5" >
<input type="hidden" name="Tsize" value="">
</form>

I've tried to simplify it by taking out any code
T.I.A
 
M

McKirahan

Roy Adams said:
Hi I'm reposting this question because for some reason can't post
follow up question to this thread.
What I'm trying to do is put the value and text from a a select in to
a text field and to a hidden field respectfully and the value from
dynamically created hidden fiields in to a text fieldin to a text
field all at the same time

[snip]

Your description and your logic conflict.

Could you rewrite the above using your form field names?
 
F

Fred Oz

Roy said:
Hi I'm reposting this question because for some reason can't post
follow up question to this thread.
What I'm trying to do is put the value and text from a a select in to
a text field and to a hidden field respectfully and the value from
dynamically created hidden fiields in to a text fieldin to a text
field all at the same time
Here's the code as viewed through the browser
<body bgcolor="#FFFFFF" text="#000000" >

<SCRIPT LANGUAGE=JavaScript>

The language attribute is dead and buried, use type:


Hiding scripts hasn't been necessary since Netscape 2, don't bother.
function ch_price (theForm) {
// this changes the price in the price text field
for (i=0; i < 2; i++){
document.form1.oldprice.value = document.form1.prevprice.value;//
the hidden fields


It is your job to make sure lines aren't inappropriately wrapped,
always wrap at about 65 characters to allow for a couple of quoted
replys

[...]
<form name="form1" method="post" action="" >
<select name="size" id="size" onChange="ch_price(form1)">
<option selected value="189.00">Select
Size/Colour</option>

Get rid of tabs, use 2 (preferred) or 4 spaces for indenting.
<option value="179.00" >95x75cm; 37x29"</option>
<option value=" 89.00" >95x75cm; 37x29"</option>

Supposed to be selecting siz/color, how does this relate?
<input name="oldprice" class="price" type="text" id="oldprice"
readonly = true value="189.00" size="5" >

Attribute values should be quoted, but readonly doesn't need one. You
may want to put readonly="readonly", but that may fool some browsers
that don't expect it to have a value.

Also, somewhere you used // to comment in HTML - that won't work, you
need to use <!-- -->

[...]

Below is an example of what you are trying to do. Post again if you
need further help.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Copy Text & Values</title>

<script type="text/javascript">

function ch_price (sel,theForm) {

// Get the options array
var opts = sel.options;


// for each option
for (i=0; i < opts.length; i++) {

// if it is selected
if (opts.selected && i > 0) {

// copy the value to the value inpput
theForm.elements['valueField'].value = opts.value;

// copy the text to the text inpput
theForm.elements['hiddenField'].value = opts.text;

} else if (i == 0) {
theForm.elements['valueField'].value = '';
theForm.elements['hiddenField'].value = '';
}
}
}

</script>
</head>
<body>

<form name="form1" id="form1" method="post" action="" ><p>
<select name="size" id="size" onChange="ch_price(this,this.form)">
<option value="" selected>Select Size/Colour</option>
<option value="value1" >Text one</option>
<option value="value2" >Text Two</option>
</select><br><br>

<!-- hidden fields that holds value for the oldprice txt field -->
<input type="text" name="valueField" value="" readonly>
<input type="text" name="hiddenField" value="" readonly>
</p></form>

</body>
</html>
 
D

Dr John Stockton

JRS: In article <41c7bee9$0$25868$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 21 Dec 2004 16:11:23, seen in
news:comp.lang.javascript said:
It is your job to make sure lines aren't inappropriately wrapped,
always wrap at about 65 characters to allow for a couple of quoted
replys

Recommendations vary in the range 64-76, but the accepted norm is 72.
That allows sufficient room for reasonable quoting without reaching 80
characters. An unnecessarily small figure, while perfectly OK for
ordinary text, in restrictive for program material. You yourself appear
to be using 72.
 

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,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top