Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  67] [ 2]  / answers: 1 / hits: 16585  / 10 Years ago, sun, november 30, 2014, 12:00:00

Here's my code in the tag:



<script>
function saveQuantity(quantity)
{
$.ajax({

alert(quantity);

})
}
</script>


and here's my HTML:



<form name=frmQuantity>
<select name=owned id=owned onChange=saveQuantity(this.value);>
<option selected=selected value=0>0</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9+>9+</option>
</select>
</form>


Why isn't this working? What am I doing wrong?


More From » jquery

 Answers
13

For what you are writing you don't need ajax, but I guess you want to do an ajax call and on success alert.



If you only want to alert, this will do the trick:



<script>
function saveQuantity(quantity){
alert(quantity);
}
</script>


To do an ajax call and alert on success, do it like this:



<script>
function saveQuantity(quantity)
{
$.ajax({
url:/path/to/executing_script.php,
type:POST,
data:{quantity : quantity}
success:function(data){
alert(data);
}

});
}
</script>


You need to echo the updated quantity on the executing_script.php to show it in your alert


[#68652] Thursday, November 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyonna

Total Points: 521
Total Questions: 104
Total Answers: 96

Location: Samoa
Member since Tue, May 3, 2022
2 Years ago
;