Bruce Gust
asked on
I'm using JQuery, I'm submitting a form and opening up a sidebar. How?
Head out to http://brucegust.com/kitchen/stunt_double.php, choose your options from the pulldowns and then click on "add to cart." The next page is "ajax.php" and it adds what you just selected into the database then lists what you just selected from the same table according to the session id.
Here's my JQuery:
Now, head out to http://brucegust.com/kitchen/door_shop.php?door_id=389&product_id=36#. I'm trying to do the same thing, but in the context of a sidebar that pops out when you click on the "add to cart" button.
Go ahead and give it a shot and see what happens...
Once you select your options and hit "add to cart," nothing happens. Click on "cancel" and you'll see the alert box that shows all of the posted values and then the sidebar opens up.
How?
Here's my JQuery:
<script>
$(document).ready(function() {
$("#myForm").submit(function(e) {// use the correct ID
e.preventDefault();// we don\'t want to submit anything until we\'ve first determined that the user\'s not get ready to duplicate something that\'s already in the database.
var devTest = $( "#myForm" ).serialize(); //packaging all of our submitted variables into one, neat little var
alert("Develop test, URL prams = "+devTest);// publish a little alert box that lets you see your posted variables
$.post( "ajax.php", devTest) // posting all of our variables to ajax.php
.done(function(Drumstick) { //the "done"function is what you\'re doing when the AJAX call (in this case the ajax.php page) is "done" running and we\'re now hearing back from the server
if (Drumstick.charAt(0) == "E") //"Drumstick.charAT(0) is just fancy code for the first letter of what you\'re getting back from the server
{
alert("ERROR - The submarket has been entered before");
}
else
{
alert(Drumstick);
//url="update_insert_success.php?id="+Drumstick;
//window.location.href=url;
}
});
});
});
</script>
Now, head out to http://brucegust.com/kitchen/door_shop.php?door_id=389&product_id=36#. I'm trying to do the same thing, but in the context of a sidebar that pops out when you click on the "add to cart" button.
Go ahead and give it a shot and see what happens...
Once you select your options and hit "add to cart," nothing happens. Click on "cancel" and you'll see the alert box that shows all of the posted values and then the sidebar opens up.
I want the sidebar to be the "ajax.php" content like what I have in the first scenario.
I want the sidebar to open up after I click on "add to cart."
I want the sidebar to open up after I click on "add to cart."
How?
Currently you have 2 buttons on the form - Cancel and Add To Cart. The Cancel button is an input type="image" while the Add To Cart button is just and image. Because of this, the Cancel button is the only one that actually submits your form - the Add To Cart button is just an image in a link so has no behaviour. You might want to swap the button types around
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, gentlemen!
ASKER
Guys, since posting this question I was assigned another project that had me becoming more familiar with JQuery and Ajax and I was able to get my page working thanks to that "baptism" as well as your comments.
Thanks!
Thanks!