I have this code that works perfectly in Firefox, but I can not get it to work in IE.
The user can only choose 10 units in total and when he reaches 10 he displays a alert()
.
Does anyone have an idea or a better solution?
Here the JSfiddle
function getval() {
var inputs, index,liste;
inputs = document.getElementsByTagName('input');
for(var key in inputs) {
var value = inputs[key].value;
var id = inputs[key].id;
if (value > 0) liste =liste+id+"-"+value+";";
}
alert(liste.replace("undefined",""));
}
function mysum() {
var inputs, index,liste;
nbbroca=0;
inputs = document.getElementsByTagName('input');
for(var key in inputs) {
var value = inputs[key].value;
if (value > 0) nbbroca += parseInt(value);
}
if (nbbroca >= 10) alert(nbbroca);
}
$(":input").bind('change', function () {
mysum();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><center><formmethod="post" onsubmit="getval()">
<table id="products" name="products" class="products">
<tr class="figures">
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
<th>
<a href="#">
<figure>
<img src="http://s33.postimg.org/j2so2jo1b/image1.png"alt="Product name" class="ProductTopCell img-rounded">
<p></p>
</figure>
</a>
</th>
</tr>
<tr class="quantity">
<td>
<input id="1011" name="1011" type="number" min="0" value="0" >
</td>
<td>
<input id="1012" name="1012" type="number" min="0" value="0" >
</td>
<td>
<input id="1013" name="1013" type="number" min="0" value="0" >
</td>
<td>
<input id="1014" name="1014" type="number" min="0" value="0" >
</td>
<td>
<input id="1015" name="1015" type="number" min="0" value="0" >
</td>
<td>
<input id="1016" name="1016" type="number" min="0" value="0" >
</td>
</tr>
</table>
<button type="submit">Post</button>
</form>
</center>