son Posted October 19, 2009 Share Posted October 19, 2009 I have an input to change quantities of items in shopping cart and to delete an item (PHP-generated code) as:<input type="text" style="width: 2em" name="qty[56]" value="5" /> <a href='#'><img src='assets/delete.gif' width='15' height='15' alt='Click to remove item' onclick="document.forms['cart'].elements['qty[56]'].value='0'; document.forms['cart'].submit()"></a>Clicking onto delete.gif does set the quantity to '0', but it does not remove the item (which would happen when you enter '0' into input name="qty[56]" and pressed the submit button.The submit button is as:<input type=\"submit\" value=\"Update Total\" id=\"submit\" name=\"submit\" />There is also a hidden value as:<input type=\"hidden\" name=\"do\" value=\"update\" />Therefore I tried:<input type="text" style="width: 2em" name="qty[56]" value="5" /> <a href='#'><img src='assets/delete.gif' width='15' height='15' alt='Click to remove item' onclick="document.forms['cart'].elements['qty[56]'].value='0'; onclick="document.forms['cart'].elements['do'].value='update'; document.forms['cart'].submit()"></a>How can I correctly incorporate the hidden input?Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2009 Share Posted October 19, 2009 You have 2 onclick handlers. You can only have one, combine your code. Your quotes are also a little messed up. Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 You have 2 onclick handlers. You can only have one, combine your code. Your quotes are also a little messed up.I have only once 'onclick', start and end with double quotes and have two bits separted with a colon. What is exactly wrong? Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2009 Share Posted October 19, 2009 You have this:onclick="document.forms['cart'].elements['qty[56]'].value='0'; onclick="document.forms['cart'].elements['do'].value='update'; document.forms['cart'].submit()"According to the quotes, this is what you are assigning to onclick:onclick="document.forms['cart'].elements['qty[56]'].value='0'; onclick=" Link to comment Share on other sites More sharing options...
jeffman Posted October 19, 2009 Share Posted October 19, 2009 Jinx Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 Now I see what you mean. In meantime I had already changed the code to:onclick="document.forms['cart'].elements['qty[56]'].value='0'; document.forms['cart'].submit()"with the same result. It sets it correctly to 0, but does not submit the form...Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2009 Share Posted October 19, 2009 Are you checking for Javascript errors? Write out document.forms['cart'] to the Firebug console and see if it points to the correct form. It would probably be better to use document.getElementById instead of document.forms. Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 Are you checking for Javascript errors? Write out document.forms['cart'] to the Firebug console and see if it points to the correct form. It would probably be better to use document.getElementById instead of document.forms.Would like to. Struggling with my console. It says 'Reload to activate window console', but nothing happens when I reload page...Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2009 Share Posted October 19, 2009 It always shows that message, if you use console.log instead of alert to write something out you should see it appear in the console tab. Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 It always shows that message, if you use console.log instead of alert to write something out you should see it appear in the console tab.Now I am totally lost. To be honest, with javascript I am not sure what you mean by writting something out...Son Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2009 Share Posted October 19, 2009 Use console.log(document.forms['cart']) in your Javascript code, it will show something in the Firebug console. Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 Use console.log(document.forms['cart']) in your Javascript code, it will show something in the Firebug console.Thanks. It shows:<form id="cart" name="cart" method="post" action="cart-page.php">It says now: document.forms.cart.submit is not a functionSonInserted ... at the end which might be misleading Link to comment Share on other sites More sharing options...
son Posted October 19, 2009 Author Share Posted October 19, 2009 Thanks. It shows:<form id="cart" name="cart" method="post" action="cart-page.php">It says now: document.forms.cart.submit is not a functionSonInserted ... at the end which might be misleadingFound what caused the issue: the submit button has an id and name of 'submit'. Renaming the submit eradicated the issue. Many thanks for your input...Son Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.