scriptygoddess

23 Mar, 2007

Setting Form Elements (mini-cheatsheet)

Posted by: Jennifer In: Javascript

Just some random stuff. This post was saved as a draft a long time ago because I needed to refer to one of these – but was waiting until I could find the original source to publish. It's pretty generic/basic stuff, though, (and a really small snippet) so I'm finally posting it.

To set the value of a text element, the following syntax is used:
document.formName.elementName.value = elementValue;

To set a select element, the following syntax is used:
document.formName.elementName.selectedIndex = elementValue;(also see this post: Javascript Sect Selection in Select Element)

To set a radio element, the following syntax is used:
document.formName.elementName[elementValue].checked = true;

To set a checkbox element, the following syntax is used:
document.formName.elementName.checked = true

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

No Responses to "Setting Form Elements (mini-cheatsheet)"

Comment Form

Featured Sponsors


  • Michael: You can use get_header(2) in your case. The filename of your custom header has to be header-2.php. The problem with include(your_file.php) is, all
  • cliff: hi wonder if you can help me, pls i designed www.kouga.mobi using dreamweaver CS3 and now want to make the phonenumbers into links so that if you
  • jerey: how do i rewrite this because it tried RewriteEngine on #Options +FollowSymlinks RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FIL

About


Advertisements