TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 04-29-2009, 03:21 AM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default 2 or more forms don't want to play along nicely..

Right, I have an ajax cart and this is my problem. I have a form that submits an id through AJAX. This form is recognised through its class form. See the JS below. Anyway, this works fine for 1 form with class value form, but once there are more than 1 product/form it breaks - the first form will only submit, if i submit other forms, the first one is submitted still.

PHP Code:
<?php
require_once( '../config.php' );
?>
$(document).ready(function(){
    var inputId = $("#product_id");
    var inputAmount = $("#product_amount");
    var loading = $("#loading");
    var cartContent = $(".box > ul");
    
    function updateCart(){
        cartContent.hide();
        loading.fadeIn();
        $.ajax({
            type: "POST", url: "<?php echo ROOT_URL?>index.php?act=cart", data: "&action=update",
            complete: function(data){
                loading.fadeOut();
                cartContent.html(data.responseText);
                cartContent.fadeIn(2000);
            }
        });
    }
    function checkForm(){
        if(inputId.attr("value") && inputAmount.attr("value"))
            return true;
        else
            return false;
    }
    
    updateCart();

    $(".form").submit(function(){
        if(checkForm()){
            var id = inputId.attr("value");
            var amount = inputAmount.attr("value");
            $(".send").attr({ disabled:true, value:"Sending..." });
            $(".send").blur();
            $.ajax({
                type: "POST", url: "<?php echo ROOT_URL?>index.php?act=cart", data: "&action=insert&product_id=" + id + "&product_amount=" + amount,
                complete: function(data){
                    cartContent.html(data.responseText);
                    updateCart();
                    $(".send").attr({ disabled:false, value:"Add to cart" });
                }
             });
        }
        else alert("Please fill all fields!");
        return false;
    });
});
How could I get this JS to accept more than 1 form? And what would I have to change in my HTML/call?

Thanks for looking!
Sam Granger is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on PHP MYSQL Forms Input deesudesu Absolute Beginners 1 03-20-2009 10:50 AM
How many of you play Wow? codefreek The Lounge 10 12-08-2008 11:44 PM
Sending forms using Jooney Rendair Advanced PHP Programming 1 04-17-2008 06:29 AM
How do you handle forms? maZtah General 13 03-14-2008 10:13 PM
Coding nicely Tanax General 3 12-05-2007 05:20 PM


All times are GMT. The time now is 03:26 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design