SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Show/Hide Form Fields with preset values?

    I've got a form which will show extra fields if a user clicks on an option from a different field. That all works fine. My problem is how do I show the secondary options based on another field if that field is preset to a value?

    More specifically, my form, after submitted, will show a confirmation page with all of the form fields shown as disabled but populated with the data that was entered. My current javascript code uses event handlers to catch when a form field is clicked on (in particular I'm using radio buttons) to show or hide other fields depending on which option is checked. The confirmation page is keeping the secondary fields hidden because the first field is not clicked on. It is however set properly based on the user's input before submitting the form. So how would I check the form field's value after the form is submitted to redisplay the appropriate secondary fields?
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than choosing to display the fields or not in the confirmation page based on what the user clicks on, base it on which form parameters have been set (using server-side scripting).

  3. #3
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that is an option but I would like to know how to do it as I asked with Javascript?!?
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    You would use the following

    Code javascript:
    function processForm() {
       ...
    }
    document.getElementById('myForm').onsubmit = processForm;

    this.elements accesses array of form elements, and this.getElementsByName('myName')[0] is the first of the named elements.
    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
  •