SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: text changing

  1. #1
    SitePoint Addict Feudalism's Avatar
    Join Date
    Jun 2002
    Location
    Buenos Aires, Argentina
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question text changing

    When list-field changes, it should automatically change some text.

    HTML Code:
    <select name="part" class="input_text">
         <option value="1"> Motor </option>
         <option value="2"> Steel </option>
         <option value="3"> Glass </option>
    </select>
    
    <p>Price for each [part] is : 20 </p>
    The "[part]" text should change dinamically

  2. #2
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    529
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you'll wanna do something like this...

    javascript
    Code:
    function changeText(menu) {
         document.getElementById("change-this").innerHTML = menu.options[menu.selectedIndex].innerHTML;
    }
    html
    Code:
    <select name="part" class="input_text" onchange="changeText(this);">
         <option value="1"> Motor </option>
         <option value="2"> Steel </option>
         <option value="3"> Glass </option>
    </select>
    
    <p>Price for each <span id="change-this">whatever</span> is : 20 </p>

  3. #3
    SitePoint Addict Feudalism's Avatar
    Join Date
    Jun 2002
    Location
    Buenos Aires, Argentina
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent... now, how can I make this function to be active from the begining, at no change event? Eg: If at the beginning it's selected some value (it hasnt changed yet)

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    529
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe something like this...

    javascript
    Code:
    window.onload = function() {
         changeText(document.getElementById("part"));
    }
    html
    Code:
    <select name="part" id="part" class="input_text" onchange="changeText(this);">
         <option value="1"> Motor </option>
         <option value="2"> Steel </option>
         <option value="3"> Glass </option>
    </select>
    when the window is loaded it will call on that function, looking at your menu ("part") and seeing what is currently selected.

  5. #5
    SitePoint Addict Feudalism's Avatar
    Join Date
    Jun 2002
    Location
    Buenos Aires, Argentina
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where should I place the 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
  •