SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cycle through form and populate with values from JS object

    I want to loop through a form containing various fields and replace them with values I have in a JS object.

    E.g.

    (1)

    <form id="theform">
    <input type="text" name="field_1" value="" />
    <input type="checkbox" name="field_2" value="" />
    </form

    (2)

    object.field_1 = "Dave";
    object.field_2 = ""; // empty as not checked, else holds value of checked one

    --

    The problem is: what about checkboxes and <select> drop downs, and radios??

    Is there a script like this around as I'm guessing this could be useful for Ajax to populate input boxes in some situations (depending on the content etc.) so I'm guessing I'm not the only one who needs this?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by johnsmith153 View Post
    The problem is: what about checkboxes and <select> drop downs, and radios?
    A script can determine which of those types of fields a given form field is from its nodeName and type attribute, and automatically adjust its behaviour based on which one it is.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •