Computing.Net > Forums > Programming > Java script parse to HTML value

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java script parse to HTML value

Reply to Message Icon

Name: Octopus
Date: March 2, 2009 at 21:52:10 Pacific
OS: Windows Vista
CPU/Ram: 5200/6GB
Product: Foxconn / CUSTOM
Subcategory: Java
Comment:

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...

HTML Code
<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 );

OR

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

OR a series of

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

</script>


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

Thanks.

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



Sponsored Link
Ads by Google

Response Number 1
Name: RBAK
Date: March 6, 2009 at 08:50:17 Pacific
Reply:

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.

RB



0

Response Number 2
Name: shutat
Date: March 6, 2009 at 11:37:34 Pacific
Reply:

Do you mean something like below?

<html>
<head>
<script language="javascript">

function randID() {

   var d = new Date();

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

</script>
</head>
<body onload="randID()">
<input id="locked" value="" disabled="disabled">
</body>
</html>


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java script parse to HTML value

Using Java Script to write to a tex www.computing.net/answers/programming/using-java-script-to-write-to-a-tex/3283.html

Java script / Menu to Sub menu problems www.computing.net/answers/programming/java-script-menu-to-sub-menu-problems/1968.html

Java Script www.computing.net/answers/programming/java-script/18694.html