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

4
  • Can you show the whole JS code that applies, not just that one .click() line? Commented Mar 31, 2013 at 1:28
  • I dont have that code? That's the problem.. :( Commented Mar 31, 2013 at 1: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? Commented Mar 31, 2013 at 1: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. Commented Mar 31, 2013 at 1:39

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

4 Comments

I have tried that but the page responds differently to that compared to a manual click...
For the demo you are talking about, you are trying to submit the form, correct? You've tried .submit() instead of .click()?
I tried both!? Aswell as manually click my generated button.. I can't understand how a manual click would produce different results from .click?
It shouldn't, you are right. Sorry, I dont have something else for you to try. Someone else will come along that might.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.