Java script parse to HTML value

Foxconn / CUSTOM
March 2, 2009 at 21:52:10
Specs: Windows Vista, 5200/6GB
So maybe I am using the wrong keywords on Google but I can find how to...

Take a value generated by Java script and put into a HTML input value. My attempted code may make more sense. I am attempting to generate a random ID to be placed in an input value field that is non-editable. So...

<td><input type="text" name="itemID" size="20" disabled="disabled" value=" '+ID+' ">

Java Script
<script type="text/javascript">

var d = new Date()
var ID = d.getDate()+""+d.getMonth() + 1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();
document.write(ID );


document.write("<INPUT name=\"itemID" + "value=\" + "ID" + " + ">" );

OR a series of

document.write(" <INPUT name=\"q")
document.write("\" value=\"\">")


I figure this would be fairly easy to do. Let me know if you know anything.


2 gb RAM ATI,
AMD 5200
Thermaltak SVKing Case
XFX 7600 GT
550W Antec TruPower

See More: Java script parse to HTML value

Report •

March 6, 2009 at 08:50:17
If you're trying to set a dynamic id in the html so that if its posted back the value goes with it then you can try:

1) Adding a hidden field to the html
<input type="hidden" name="dynamicId">

2) Set the value in the javascript:
document.formname.dynamicId.value = ID;

Obviously the html structure you use will effect how you can access the dynamicId field but hopefully this should help.


Report •

March 6, 2009 at 11:37:34
Do you mean something like below?
<script language="javascript">

function randID() {

   var d = new Date();

   document.getElementById("locked").value = Math.ceil(Math.random() * d.getTime());

<body onload="randID()">
<input id="locked" value="" disabled="disabled">

Report •

Related Solutions

Ask Question