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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically set values in a form textbox and list?

Status
Not open for further replies.

humour

Programmer
Nov 24, 2003
87

I simply want to dynamically or programatically set the values in an HTML form - specifically the values in a list and the value in a text box. I think Javascript should be able to do it I just haven't found a code fragment for it.

I have been trying something like the following below (doesn't work):
<form>
<input name=&quot;startdate&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot;>
<script=JAVASCRIPT>
<!--
form.startdate.value=&quot;zzzz&quot;
-->
</script>
</form>
 
Add an id attribute to your input..say id=&quot;startdate&quot;. Now try using document.getElementById(&quot;startdate&quot;).value = &quot;zzz&quot;;

If its a select box then you can iterate through the list...
for( var i=0; i < document.getElementById(&quot;selectid&quot;).options.length; i++){
document.getElementById(&quot;selectid&quot;).options = &quot;value&quot;;
}
 
sorry... should read as this
for( var int=0; int < document.getElementById(&quot;selectid&quot;).options.length; int++){
document.getElementById(&quot;selectid&quot;).options[int] = &quot;value&quot;;
}
 
Maybe this would be better for select lists:

Code:
for (var j=0; j<document.getElementById(&quot;selectid&quot;).options.length; j++)
{
   document.getElementById(&quot;selectid&quot;).options[j].value = &quot;value&quot;;
}

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top