I want to create an eshop basket.. so i want to count items up when i press a buy button. I tried to use getElementById and simple call the name of id in my basket.
—
<script type="text/javascript">
var index = 0;
</script>
somewhere in the top —–
<div>items :<input type="text" id="tb" style="width: 20px; color:green; font-weight:bold; border:none; background: none; margin-left:20px;"/></div>
and when i press the buy button ——-
<input name="button" type="submit" value="add to basket" onClick="index = index + 1;document.getElementById('tb').value = index;" />
so this is worked .. but know i want to duplicate the basket and have it twice in the page ( in the top and in the end ) so if i tried to call again the same id it just don’t work (cause the uniqueness of id). I suppose i should use classname istead but i don’t know how ..
I’m more than new to js hoping for a solution.
Thanks
You could duplicate
document.getElementById('tb').value = indexand use a second (unique) id. Or you iterate overdocumnet.getElementsByName('elementsname'), but yourinputwould have to have anameattribute.