...

View Full Version : Send Variable to function



timgraham
12-03-2008, 06:01 AM
Hi All,

I have the following two functions.



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:


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

abduraooft
12-03-2008, 07:59 AM
To send another one, you need to include it in the function call and function header.

onClick="CartAjaxModule('CartLoading437','cartAction.php','action=RemoveItem&seller_id=1&item_id=437','forth-parameter');"

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

barkermn01
12-03-2008, 06:14 PM
Hi All,

I have the following two functions.



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:


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});

timgraham
12-04-2008, 12:33 AM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum