I have a problem using the selected value from a form in jquery. It is closely related to:
I have tried for hours getting this work using the above (and other) examples.
I have a drop down list with account numbers:
<form id="accounts">
<select>
<option value="">Select one</option>
<c:forEach var="custAccount" items="${customerAccounts}">
<option value=${customerAccount}>${customerAccount.accountId}</option>
</c:forEach>
</select>
</form>
I want to use the selected account in an href:
<a href="Controller?&accountid='+selectedAccount+'&username=${username}&userid=${userid}&command=customerNewTransaction">Start new transfer</a>
And here is my script:
<script type="text/javascript">
$(document).ready(function() {
var selectedAccount;
$("#accounts").change(function() {
selectedAccount = $(this).text();
});
});
</script>
This doesn't work and the selected text is empty every time. I have also tried calling .val() aswell with the same (lack of) result.
What am I missing?