Hi I am new to javascript and I created my form just I have only one problem my function count () works with text field outside form tags but when i add those two text fields inside form tags function count() doesnt work any help please? My code: <script type="text/javascript"> function count() { var qua = document.getElementById("quantity").value; var cost = 50 var total = qua*cost document.getElementById("count").value = total; } </script> <form> <input name="quantity" type="text" id="quantity" onblur="count()" value="0" size="5" maxlength="5" /> <input name="price" type="text" value="0" size="10" id="count" maxlength="10" readonly="true" /> </form>
Found what was wrong I used id of input Count same as function Count()... when i changed id of input to anything else it works. Just dont know why it works with same id of input and same name of function when it is not close in form tags...
probably because it is trying to access 'count' as an object within the form rather then the global functoin that you want it to access.