Results 1 to 6 of 6

Thread: Passing value variable in dropdown menu to a button

  1. #1
    Join Date
    Jan 2009
    Location
    Calgary Alberta
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Passing value variable in dropdown menu to a button

    Hi all,

    I am currently working on a web-page that parses an XML file and puts it into HTML. What I have are three sorting buttons to sort the rows to list them alphabetically etc. The code for the buttons is below and it is working perfectly fine.

    Code:
    <INPUT TYPE=BUTTON VALUE="Sort By Name" onclick="sort(sortName.XMLDocument);">
    <INPUT TYPE=BUTTON VALUE="Sort By Patient ID" onclick="sort(sortNumber.XMLDocument);">
    <INPUT TYPE=BUTTON VALUE="Get Names A through M" onclick="sort(getAtoM.XMLDocument);">
    What I want to do though is take away the buttons and make them a dropdown list and a go button. I have tried the following code and it doesn't work.


    Code:
    <form name="docSortList">
    <select name="sort">
    <option value="sort(sortName.XMLDocument);">Sort By Name</option>
    <option value="sort(sortNumber.XMLDocument);">Sort By Patient ID</option>
    <option value="sort(getAtoM.XMLDocument);">Get Names A through M</option>
    </select>
    <input type="button" onClick="location=document.docSortList.sort.options[document.docSortList.sort.selectedIndex].value;" value="GO">
    </form>
    When I click on the go button, it opens up a blank page.

    I have a feeling it has something to do with the "location=document......." since I am not wanting it to go to a location, i want it to carry out an action.

    Still working on it but any guidance would be greatly appreciated.

    Thanks.
    B
    Last edited by brent.fraser; 08-21-2009 at 08:04 PM.

  2. #2
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    looks like you need an if statement... let me think it over for a few and ill have something for you to try out

  3. #3
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    on second thought, try this:
    Code:
    <form name="docSortList">
    <select id="sort" name="sort">
    <option value="sort(sortName.XMLDocument);">Sort By Name</option>
    <option value="sort(sortNumber.XMLDocument);">Sort By Patient ID</option>
    <option value="sort(getAtoM.XMLDocument);">Get Names A through M</option>
    </select>
    <input type="button" onClick="location=document.getElementById('sort').value;" value="GO">
    </form>
    theoretically this should work, though im not too familiar with XML so im unsure of your address syntax, but the same syntax should work if you did this:
    Code:
    <form name="docSortList">
    <select id="sort" name="sort">
    <option value="http://yahoo.com">Yahoo!</option>
    <option value="http://google.com">Google</option>
    <option value="http://bing.com">Bing</option>
    </select>
    <input type="button" onClick="window.location=document.getElementById('sort').value" value="GO">
    </form>

  4. The Following User Says Thank You to thenajsays For This Useful Post:

    brent.fraser (08-21-2009)

  5. #4
    Join Date
    Jan 2009
    Location
    Calgary Alberta
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi there thenajsays,

    Thank you for your help. Unfortunately it isn't working but I did find something that is at least pointing me into the right direction. I had the following code
    Code:
    <form name="docSortList">
    <select name="sort">
    <option value="sort(sortName.XMLDocument);">Sort By Name</option>
    <option value="sort(sortNumber.XMLDocument);">Sort By Patient ID</option>
    <option value="sort(getAtoM.XMLDocument);">Get Names A through M</option>
    </select>
    <input type="button" onClick="location=document.docSortList.sort.options[document.docSortList.sort.selectedIndex].value;" value="GO">
    </form>
    where I have "code" in as two different variables. I changed the name of the select so that it isn't "sort."

    I still think the issue is the whole
    Code:
    onClick="window.location=document
    thing as I don't want to open another window. I just want it to parse the XML file I have in the list value.

    Still plugging away at it.....

    Thanks again for taking a stab at it.

    B

  6. #5
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    If I understand you well, you want a function to be executed if an option of a select box is clicked on. I wrote something about it here. Take what you need.
    Arie Molendijk.

  7. The Following User Says Thank You to molendijk For This Useful Post:

    brent.fraser (08-21-2009)

  8. #6
    Join Date
    Jan 2009
    Location
    Calgary Alberta
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Thank you

    Hi there molendijk,

    I just wanted to thank both you and thenajsays for your help.

    It is now working from implementing your code.

    I appreciate your help in this.

    Have a great day both of you!
    Brent

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
  •