Help - Search - Members - Calendar
Full Version: populating a form field with js
HTMLHelp Forums > Programming > Client-side Scripting
MaristBrandi
Good morning all,

I'm trying to figure out how to properly populate a select field in an html form with javascript. I have set an onload event in the body that will automatically populate the field when the page is loaded. I just can't seem to find the right command to make the js function populate the field.

Any ideas?

Thanks!
Christian J
See http://www.javascriptkit.com/javatutors/selectcontent.shtml

Note that search engines and browsers without JS cannot see the changes.

QUOTE
I have set an onload event in the body that will automatically populate the field when the page is loaded.

Why use JS for this then? A server-side script is more reliable.
Darin McGrew
QUOTE(Christian J @ Sep 20 2007, 07:13 AM) *
Why use JS for this then? A server-side script is more reliable.
My thoughts exactly.
Brian Chandler
QUOTE(Darin McGrew @ Sep 20 2007, 11:43 PM) *

QUOTE(Christian J @ Sep 20 2007, 07:13 AM) *
Why use JS for this then? A server-side script is more reliable.
My thoughts exactly.


If this "prepopulation" consists simply of fixed values, you can replace the JS by writing the values directly in the html. No server-side script at all.

If the "prepopulation" involves variable values, you will need a server-side anyway, in order to write the javascript to put them in the form. So you can remove the JS by writing them directly into the html.

In both cases the js serves no purpose at all.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.