开发者

Firefox javascript problem setting variable

i have made a little javascript script that sets a value (named here stock), which i want to make maximum in a drop down list. it will be the maximum value if it is greater that 6.

Here is the code:

<script type="text/javascript"> 
function selecteazaElement(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++)
{
    //alert ('id: '+id开发者_运维问答+'; stock: '+stock);
    number23.options[number.options.length]=new Option(i, i);
}
    //window.status="my status";
    } 
  </script>

i use this code in this 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>

So after the user chooses a product,form a list he can also choose a number(of products) my problem is:

It works perfectly in chrome and opera, but doesn't display the numbers in the drop down list in Firefox. i wonder why is that?

Thank you!


This line is causing the problem in Firefox:

number23.options[number.options.length]=new Option(i, i);

Change it to:

number23.options[number23.options.length]=new Option(i, i);

and it will work.

Your original code: http://jsfiddle.net/CS6uv/1/ (doesn't work in Firefox)

Corrected code: http://jsfiddle.net/CS6uv/2/ (works in Firefox)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜