...

View Full Version : how can i put the value of a javascript variable into a form text value



bungi
09-24-2003, 04:54 PM
Hi i have a form page as follows

<script language="JavaScript" TYPE="text/javascript">
<!--

var catnoval = 'test';

//-->
</script>

<form action="##" method="post" name="amendform" id="amendform">

<input type="Text" name="packcode" class="FormFieldSelect165px" value="<script language="JavaScript" TYPE="text/javascript">docuemt.writeln(catnoval );</script>">

</form>


When i want to view the form i get the whole '="<script language="JavaScript" TYPE="text/javascript">docuemt.writeln(catnoval );</script>' beeing displayed and not the actual value of the javascript variable! i.e 'test'

Can anyone help me on how i can display this javascript variable inside the value attribute of the form's text element?

Any help appreciated
Thanks
Zubair

Vladdy
09-24-2003, 05:13 PM
<script type="text/javascript">
var myVar='test value';

function initPage()
{ document.getElementById('myInput').value=myVar;
return;
}
</script>
...
<body onload="initPage()" ...


<input id="myInput" name="myInput" type="text" value="" />


Out of curiosity, where did you get your code???

beetle
09-24-2003, 05:14 PM
<html>
<head>
<script type="text/javascript">

var catnoval = 'test';

function init()
{
document.forms['amendform'].elements['packcode'].value = catnoval;
}

</script>
</head>

<body onload="init();">

<form action="##" method="post" name="amendform" id="amendform">

<input type="Text" name="packcode" class="FormFieldSelect165px" value="">

</form>

</body>
</html>

Vladdy
09-24-2003, 05:16 PM
:D :D beat you this time, beetle :D :D

beetle
09-24-2003, 05:19 PM
*waves fist*

<grandpa simpson>
Darn you! Ahhhhh!
</grandpa simpson>

:p

liorean
09-24-2003, 05:51 PM
LoL - usually it's the defeated one that acknowledges the victor and not the other way around - ie "Bleh! you beat me to it, ..."

beetle
09-24-2003, 06:17 PM
Are you kidding, I practically work for Vladdy, the slave driver.

http://www.peterbailey.net/images/web_photos/money.jpg

:p

Vladdy
09-24-2003, 06:22 PM
ROFLMAO, I thought that was another way round...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum