I have created a small JavaScript script that defines a value (referred to as stock), which I want to set as the maximum in a dropdown list. It will be set as the maximum value if it exceeds 6.
Below is the code snippet:
<script type="text/javascript">
function selectElement(id, stock) {
document.addtobasket.idOfSelectedItem.value = id;
var number23 = document.addtobasket.number;
number23.options.length = 0;
if (stock >= 6)
stock = 6;
for (i = 1; i <= stock; i++) {
number23.options[number.options.length] = new Option(i, i);
}
}
</script>
I am using this code within the following form:
<form id="addtobasket" name="addtobasket" method="POST" action="<?= Route::url('Add to Basket', array('sale_id' =>$sale->id)); ?>">
<input type="hidden" name="idOfSelectedItem" id="idOfSelectedItem" value="-1">
<select name="number" id="number">
<option value=0>Choose the number of products</option>
</select>
<button type="submit" name="submit" onclick="valbutton(addtobasket);">Adauga in cos</button><br />
</fieldset>
</form>
Upon selecting a product from the list, the user can choose the quantity as well. However, I face an issue:
The functionality works smoothly in Chrome and Opera browsers but fails to display the numbers in the dropdown list in Firefox. I am curious as to why that might be?
Thank you!