SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wonder if anyone knows of a simple tutorial for altering form elements depending on the content of others. For example, how would you make picking an item from a drop-down menu "fill-in" some text into a text field? Also, greying out a text field if a checkbox is not ticked would be useful.

    It would need to all work on non-JS supporting browsers or for users with JS disabled.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changing form element values with JavaScript is fairly straightforward. With form markup like the following:
    Code:
    <form>
    <select onChange="updateField(this.options[selectedIndex])">
    <option value="foo">This
    <option value="bar">That
    </select>
    <input type="text">
    </form>
    Then you can use something like the following:
    Code:
    function updateField(option) {
        forms[0].elements[1].value = option.value;
    }
    You change the value of the text field (element[1]) to the value of the pop-up option, in this case either "foo" or "bar."
    To make this work without JavaScript, you would need to do something with Perl or (though I don't do any of it myself) some kind of dynamic page generator like PHP.
    I hope this helps
    <<< johnny chidiac
    johnnydaboy@mac.com


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
  •