By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

writing from hidden field to text field repost

P: n/a
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[i].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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Roy Adams" <ro*******@ntlworld.com> wrote in message
news:13*************************@posting.google.co m...
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?


Jul 23 '05 #2

P: n/a
Roy Adams wrote:
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:

<script type="text/javascript">
<!--
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[i].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[i].selected && i > 0) {

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

// copy the text to the text inpput
theForm.elements['hiddenField'].value = opts[i].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>

--
Fred
Jul 23 '05 #3

P: n/a
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, Fred Oz <oz****@iinet.net.auau> posted :
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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.