Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Send Variable to function

    Hi All,

    I have the following two functions.

    Code:
    function CartAjaxModule(LoadingDiv,URL,PostData) {
    Element.show(LoadingDiv);
    new Ajax.Updater('CartData', URL, {method: 'post', parameters: PostData});
    }
    
    function CartAjaxModuleForm(LoadingDiv,URL,FormName) {
    var PostData = Form.serialize(FormName);
    Element.show(LoadingDiv);
    new Ajax.Updater('CartData', URL, {method: 'post', parameters: PostData});
    }
    Called using:

    Code:
    onClick="CartAjaxModule('CartLoading437','cartAction.php','action=RemoveItem&seller_id=1&item_id=437');"
    I want to send an extra variable to the function which will make "CartData" dynamic. Every way I try does not seem to work. Could someone kindly show me how to do this.

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    To send another one, you need to include it in the function call and function header.
    Code:
    onClick="CartAjaxModule('CartLoading437','cartAction.php','action=RemoveItem&seller_id=1&item_id=437','forth-parameter');"
    Code:
    function CartAjaxModuleForm(LoadingDiv,URL,FormName,forthOne) {
    var PostData = Form.serialize(FormName);
    Element.show(LoadingDiv);
    new Ajax.Updater('CartData', URL, {method: 'post', parameters: PostData});
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    timgraham (12-03-2008)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by timgraham View Post
    Hi All,

    I have the following two functions.

    Code:
    function CartAjaxModule(LoadingDiv,URL,PostData) {
    Element.show(LoadingDiv);
    new Ajax.Updater('CartData', URL, {method: 'post', parameters: PostData});
    }
    
    function CartAjaxModuleForm(LoadingDiv,URL,FormName) {
    var PostData = Form.serialize(FormName);
    Element.show(LoadingDiv);
    new Ajax.Updater('CartData', URL, {method: 'post', parameters: PostData});
    }
    Called using:

    Code:
    onClick="CartAjaxModule('CartLoading437','cartAction.php','action=RemoveItem&seller_id=1&item_id=437');"
    I want to send an extra variable to the function which will make "CartData" dynamic. Every way I try does not seem to work. Could someone kindly show me how to do this.

    Thanks
    This is quite ovusly not your code but if you are allowed to modify it it is realy simple you see how the variable data is passed?

    CartAjaxModule(LoadingDiv,URL,PostData)
    This meens when you call CartAjaxModule('bla','poo','didys')
    so the Var LoadingDiv becomes 'bla' the URL 'poo' ect...

    so add another one to the end CartAjaxModule(LoadingDiv,URL,PostData,cartData)
    Then just use it
    new Ajax.Updater(cartData, URL, {method: 'post', parameters: PostData});
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #4
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem Solved

    Thanks abduraooft.
    I am very new to JS. I did previously try exactly what you have explained but it didn't seem to work. I must have made a small typo because it now works fine. Thanks again for your time.

    bakermn01 -> This is my code! As I am new to JS, it took me a while to put it together, using resources from the web. The "Ajax.Updater()" is part of the Prototype library. I have developed a PHP cart that I believe is far more advanced than anything I could find on the "web self", which I am now adding ajax functions to.
    I appreciate your response, but if you have to be so negative why bother joining online communities. Hopefully I will be able to help you some day. When I do I will have a smile on my face
    Last edited by timgraham; 12-03-2008 at 11:48 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •