Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form and hidden variable question

Status
Not open for further replies.

ColdFusionKing

Programmer
Dec 5, 2002
145
GB
Hi Guys,

I desparately need somebody to help me. I have a form which has hidden variable, a textarea and a submit button. When the submit button is clicked a OnClick event calls a function subme() method. Here is my code

<form name=&quot;frm&quot; method=&quot;post&quot;>
<input NAME=&quot;update&quot; TYPE=&quot;submit&quot; ONCLICK=&quot;javascript:subme()&quot; VALUE=&quot;Calculate&quot;>
<textarea name=&quot;txtarea1&quot; cols=&quot;40&quot; rows=&quot;5&quot;></textarea>
<input type=&quot;hidden&quot; name=&quot;outputselection&quot; value=&quot;&quot;>
</form>

Here is the javacript code:

<script LANGUAGE=&quot;javascript&quot;>
function subme() {
method1();
document.frm.outputselection.value = PagecontentA + PagecontentB + PagecontentC;
alert(document.frm.outputselection.value);
document.frm.submit();
}


function method1(){
PagecontentA =&quot;Hello&quot;;
PagecontentB =&quot;And&quot;;
PagecontentC =&quot;Welcome&quot;;
}

</script>

When browsed in the browser on form submission the alert displays the value &quot;Hello And Welcome&quot; but for some reason when I view the source in the browser the value of the hidden variable &quot;outputselection&quot; is empty. I want to populate the textbox with the value in the hidden variable. I am struggling to do this. Can somebody please show me how to do this, I would really appreciate your help

Best Regards,
Allan
 
Javsacript will not change the 'View Source' value for the hidden field but it is changing. This is evidenced by your alert.

Just do

document.frm.txtarea1.value = document.frm.outputselection.value;

That will change it in the browser even though the hidden field 'looks' empty.

View Source just shows you the source at time of page generation before JS gets its hands on it.
 
I did just what you asked me to. I added this line in my code:
document.frm.txtarea1.value = document.frm.outputselection.value;

When I submit the form, the value in the hidden variable gets displayed in the textarea (briefly) but dissappears immediately when the form has submitted completely. I can't understand it. Any ideas?
 
I have found a way around this. In the onClick event of the submit button I am adding this code

<input NAME=&quot;update&quot; TYPE=&quot;submit&quot; ONCLICK=&quot;javascript:subme(); return false;&quot; VALUE=&quot;Calculate&quot;>

and in teh actual function,I'm doing this

document.frm.txtarea1.value = document.frm.outputselection.value;
return true;

Many thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top