-1

I'm building a website ontop of e-commerce framework from Sweden. For this project the client wants me to manipulate the shopping cart. In the beginning I got it working so I know there's a way to do it(I switched method, that why I lost that and some more which you can read below). But!!

I render everything on the run, and i outputs buttons which if I press the buttons manually they work like a charm. So when finishing my work I thought I could just make a function that finds all buttons and click them manually, but NO. That submits the form which takes me to a page that's that only there to increment cart quantity.

Here's the div

<form method="post" action="/shoppingcart/increase_product_count/" 
class="product_form" name="product_built_div">
<input type="hidden" value="" name="product_id" id="kontroll">
<input type="submit" value="Kontroll"></form>

When looking at request they look like this if I click manually.

1743
/legacy-template-api/conceptual-id-lookup
GET
200
OK
text/plain
cache.js:2013
Script
369 B
4 B
348 ms
347 ms
347 ms1 ms
514f4eb04b96714970000004/
/carts
POST
200
OK
application/vnd.ebutik.cart+xml
cache.js:2013
Script
1.2 KB
878 B
216 ms
214 ms
214 ms2 ms
shoppingcart/
/shoppingcart/show_widget
GET
200
OK
text/html
cache.js:2013
Script 

Clicking like this this holds the correct info, I've checked aswell as I get sent to the product increment page.

 $(this).find('input[type=submit]').click();  

Request data for JQUERY .click()

increase_product_count/
/shoppingcart
POST
(pending)

Pending then turns into not found?

I did notice that i cant't find my built div in the page source I'm using chrome broswer. Is there another issue?

8bitcat
  • 2,206
  • 5
  • 30
  • 59
  • Can you show the whole JS code that applies, not just that one `.click()` line? – Luke Shaheen Mar 31 '13 at 01:28
  • I dont have that code? That's the problem.. :( – 8bitcat Mar 31 '13 at 01:31
  • I don't understand what you are trying to do. When a user clicks a certain button, you want that button to submit the form? This button is different then the `submit` button? – Luke Shaheen Mar 31 '13 at 01:32
  • I want to autosubmit forms or auto click the button of a couple of forms to simulate putting things i the shopping cart.. It works when i manually click my buttons, but not when i want to loop over and click them. – 8bitcat Mar 31 '13 at 01:39

1 Answers1

2

To submit a form using jQuery, check out .submit()

To simulate clicks of other non-submit buttons, your .click() should work.

Alternatively to .click(), you can try .trigger("click").

Examples on using .submit()

Community
  • 1
  • 1
Luke Shaheen
  • 4,262
  • 12
  • 52
  • 82
  • I have tried that but the page responds differently to that compared to a manual click... – 8bitcat Mar 31 '13 at 01:51
  • For the demo you are talking about, you are trying to submit the form, correct? You've tried `.submit()` instead of `.click()`? – Luke Shaheen Mar 31 '13 at 01:53
  • I tried both!? Aswell as manually click my generated button.. I can't understand how a manual click would produce different results from .click? – 8bitcat Mar 31 '13 at 01:54
  • It shouldn't, you are right. Sorry, I dont have something else for you to try. Someone else will come along that might. – Luke Shaheen Mar 31 '13 at 01:59