SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Document write when an option is selected

    I have a form that starts off with a select box with two options. Required fields are determined by which of the 2 options is selected. How can I write to the form as soon as the option is selected so it has a red asterisk next to the input field to show it is required.

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to select the field or value from the options box use this

    onchange="alert(this.options[this.selectedIndex].value)"

    then select the object you want to insert

    document.all.obj or document.getElementByID['obj'] or document.layer etc

    try this tho havent tested it

    PHP Code:
    <script type="text/javascript">
      function 
    swap_element(what)
      {
        if (
    document.all.blah)
        {
          
    document.all.blah.innerHTML what.options[what.selectedIndex].value 
        
    }
      }
    </script>

    <form>
      <select onchange="swap_element(this)">
        <option value="a"> a </option>
        <option value="b"> b </option>
        <option value="c"> c </option>
      </select>
    </form>

    <span name="blah"></span> 
    and basically use a switch statement or you could generate the lot by using createElement/appendChild etc


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
  •