Click to See Complete Forum and Search --> : how to place value with javascript?


dna
03-31-2005, 04:25 AM
i need to place the value of balance inside the textbox value with the javascript code, i had tried the following code but not work.
<%
balance = ye_ent - no_days

response.write("<script> document.getElementById('balance').value =" & balance & ";</script>")
%>

buntine
03-31-2005, 04:40 AM
Try this:

<%
balance = ye_ent - no_days

response.write("<script> document.getElementById('balance').value = '" & balance & "';</script>")
%>

Regards.

dna
03-31-2005, 04:49 AM
i tried this before but it doesn't work, anyway thanks!

andrewchai
03-31-2005, 04:50 AM
Thanks !

i try this but still can not !

buntine
03-31-2005, 05:21 AM
Look at the source code of the output file. The JavaScript line should look fine. Are you getting a JavaScript error (look in the bottom left corner)?

Mayby there is no form control with the ID of 'balance'. Mayby you don't need to use JavaScript at all; why can't you just print this variable directly to the textbox? Example:

<input type="text" name="txtBalance" value="<%= balance %>" />

Regards.

dna
03-31-2005, 05:29 AM
ya, i got the JavaScript error!
i had tried that code b4, and it can works but i need to use the javascript to place the value inside the textbox....
thanks for ur code.

buntine
03-31-2005, 07:04 AM
Ok, so what is the JavaScript error? Can you post it?

athankon
03-31-2005, 09:10 AM
you can asign a javascript variable to hold the value of an ASP variable like this like: <script language="javascript">
var varName = '<%=varname%>';
and then you place it anywhere you want
</script>

Did that help?

phpnovice
03-31-2005, 09:34 AM
See: http://www.webdeveloper.com/forum/showthread.php?t=61122

dna
04-06-2005, 03:38 AM
thanks!