I built up a page on my website as a place to perform testing of functions that I write (30 or 40 of them to date). I use a drop-down box to list the functions out by function name. When one of them is selected, I use an onChange with "window.location" to fire that function via a Select Case structure, passing the index on the query string via this.selectedIndex in the OnChange. All of this worked fine until I decided that I would also like the value of the selected option (name of the function being tested) as well (not just the index value). I found through study that the window.location does not post any form values back, so they are not available. I kept on researching and found that the "location.reload" is supposed to post back the data, but that doesn't work either.
So, I figured that I could pass the option value data via the query string perhaps by using "this.selectedOptions", but that doesn't work either. I have cut and paste a snippet of the code below, which again, works fine, but I can't get the text value of the selected option.
<form action="testcodepage.asp" method="post">
<select class="rounded " name="cboSearchCategories "
onChange='window.location="<%=sRootDomain%>/testcode/template/testcodepage.asp?TestCategory=" + this.selectedIndex;'
<option value="Select One">Select One</option>
<option value="SearchEquipmentDB()">SearchEquipmentDB()-Case #1</option>
<option value="DisplaySingleItem()">DisplaySingleItem()-Case #2</option>
<option value="CreateJSONSchema()">CreateJSONSchema()-Case #3</option>
<option value="UnlockChilkatAPI()">UnlockChilkatAPI()-Case #4</option>
</select>
</form>
Please let me know if there is a way to make this work, without using a submit button. Much appreciated! Note that this code is written using ASP Classic, but would be pertinent for any form submission.
If you use
addEventListeneron the form you and listen for the change event you can get the changed form field bye.targetand the value you then bee.target.value.