Use selected index of a pulldown menu to change tha value of a text input field
Sorry for the length of this post but I wanted to explain the problem as accurately as possible.
I have maintained the web site of a small art gallery as a volunteer for several years and am now converting the site to wordpress so the gallery can take over managing the site.
The problem: I need to take an existing paypal membership form controlled by javascript (seen here) and find a jquery solution. The membership form uses the pulldown menu's selected index to change the amount of the donation. in the text input box. I have not been able to find a solution for this in any of my google searches.
First, here is the existing paypal form and javascript (edited for length):
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="clg_memberForm">
<input type="hidden" name="on0" value="Membership Type">
<select name="os0" onchange="changeValue()">
<option value="$10 DONATION">DONATION: $10</option>
<option value="$20 DONATION">DONATION: $20</option>
</select><br>
$<input type="text" name="amount" size="8" value="">
<input name="clgButton" type="submit" value="Donate" onClick="changeValue();">
</form>
//javascript for clg_memberForm form:
function changeValue(){
var price=0;
if (document.clg_memberForm.os0.selectedIndex == 0){
price = 10;
document.clg_memberForm.amount.value = price.toFixed(2);
}else if (document.clg_memberForm.os0.selectedIndex == 1){
price = 20;
document.clg_memberForm.amount.value = price.toFixed(2);
}
}
My unsuccessful attempt to code a jquery solution using a simple test form:
//jquery:
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
switch ($('#changeAmount :selected').index()) {
2 case $(this).index() == 0:
3 $("#amount").val("100.00");
4 break;
5 case $(this).index() == 1:
3 $("#amount").val("200.00");
4 break;
case $(this).index() == 2:
3 $("#amount").val("300.00");
4 break;
9 }
}
</script>
<!- Test Form: ->
<form id="testChange">
<select id="changeAmount">
<option>First</option>
<option>Second</option>
<option>Third</option>
</select><br />
$<input name="amount" id="amount" type="text" size="5" />
</form>
How can I fix this so it will do what the existing membership form does?
Thanks,
Mark