1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript onchange event listener changes text input field value for Wordpress

Discussion in 'JavaScript' started by AaronCSD, Mar 26, 2009.

  1. #1
    I have some custom drop-down menu's on a Wordpress powered site. When a user is adding a new post they will add three details to the post using the drop down menu's. For example one select box might look like this:

    <select id="car-make">
    <option value="Volvo">Volvo</option>
    <option value="Ford">Ford</option>
    <option value="Toyota">Toyota</option>
    </select>

    After the user chooses from the drop-down I want it to automatically add the value to the blog posts 'tags'. I can't modify the code that outputs the select box's else I might add <select id="car-make" onchange="update_tags();"> so it would need to be a function inside the <head> tag that listens to the specific <select> ID's and then changes the value of the <input> ID when the event happens.

    Any ideas?
     
    AaronCSD, Mar 26, 2009 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use:
    document.getElementById('car-make').addEventListener('change', myFunc, false);
    Code (markup):
    This is for firefox, opera, etc. And now for IE:
    document.getElementById('car-make').attachEvent('onchange', myFunc);
    Code (markup):
    Where myFunc is the name of the function that you want to add the text into the tags. It will be called when the user change the select box.

    Good luck :)
     
    xlcho, Mar 27, 2009 IP