PDA

View Full Version : Resolved Passing value variable in dropdown menu to a button



brent.fraser
08-20-2009, 03:05 PM
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.


<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.



<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

thenajsays
08-20-2009, 06:57 PM
looks like you need an if statement... let me think it over for a few and ill have something for you to try out

thenajsays
08-20-2009, 07:07 PM
on second thought, try this:

<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:

<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>

brent.fraser
08-20-2009, 10:40 PM
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

<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
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

molendijk
08-20-2009, 10:40 PM
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 (http://www.dynamicdrive.com/forums/blog.php?b=34). Take what you need.
Arie Molendijk.

brent.fraser
08-21-2009, 03:20 PM
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