Jump to content

Form Element Delete Button


son
 Share

Recommended Posts

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

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

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

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

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

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

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 Edited by son
Link to comment
Share on other sites

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
Found 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...