<div class='divver'>
Quantity:
<select class='box' name='qty' id='quantity'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>
</div>
<script type="text/javascript">
var s = document.getElementById("quantity");
var quant = s.options[s.selectedIndex].text;
function checkIt(){
alert (quant);
}
</script>
On success of the submission I am running checkIt.
function submitQuickview()
{
if(productForm.validate()){
//submit the form with ajax
new Ajax.Request($('product_addtocart_form').action, {
parameters: $('product_addtocart_form').serialize(true),
onSuccess: checkIt
});
}
return false;
}
What is wrong? It always alerts 1 as the quant var no matter the value of the option that is submitted. Any ideas why? Please note that I am not using jQuery and working in Vanilla or the Prototype framework.
That is because you are assigning a value to the quant variable when the page is being loaded.
In order to get the current value
1) You need to read the selected value within the checkin function
Change your code to as follows:
Or
2) Change the value when the onchange event for the select is triggered.
Something like: