SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing a forms select options

    Hi, if someone could help me with this it would be really great. I have to following code right now. A button that interacts with a select form element.

    Code:
    <input type="button" value="Edit" onclick="newWindow('/example.com/' + document.formName.selectId.options[document.formName.selectId.selectedIndex].value); " />
    It works but only if I give the form a name attribute. What would be the simplest way to do this without a form name attribute and instead use the forms id?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    From a form element, the form property refers to the form itself.

    this.form.selectId.options[this.form.selectId.selectedIndex].value
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •