SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: OnChange Help

Hybrid View

  1. #1
    SitePoint Member Karl Evans's Avatar
    Join Date
    Oct 2005
    Location
    Liverpool, United Kingdom
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OnChange Help

    Evening,

    I'm having some difficulty at the moment with a bit of javascript, I'm by no means an expert, but I'm having a go.

    Right, I'm pulling some information from a database using PHP, I'm storing this in a javascript array. So it's a little like this:

    Code:
      var comments = new array();
    Then the PHP puts the information in the array like so.

    Code:
      comments['1'] = "Comments Here";
      comments['2'] = "Comments Here Also";
    Now what I require is a function that will change the data when the corresponding option is selected in the dropdown list.

    HTML Code:
      <select name="comments">
        <option value="1">Change To comments['1']</option>
        <option value="2">Change To comments['2']</option>
      </select>
    Whatever is selected needs to be displayed underneath the dropdown list.

    Could anybody put me in the right direction please?

    If somebody can write the function that works, I will chuck them a few quid/dollars via PayPal.

    Thanks,
    Karl

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <select name="comments">
    <option value="1">Change To comments['1']</option>
    <option value="2">Change To comments['2']</option>
    </select>

    So someone selects an option, a javascript function fires and gets "comments" value
    var show_this = document.getElementById('comments').value;

    show_this is 1 or 2 now right?

    To get the data you've set with PHP do:
    comments[show_this];


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
  •