/    Sign up×
Community /Pin to ProfileBookmark

passing multiple parameters in function

Hello to all,

I can’t pass multiple parameters in a function.

Thanks,

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJul 15.2008 — You sure can. Can we see the JavaScript code you are using?
Copy linkTweet thisAlerts:
@myanavrinauthorJul 16.2008 — Here is the function that will receive the values.

function calc(itemId, rateId, totalId){

var rate = document.getElementById(rateId).value;

var item28 = document.getElementById(itemId).value;

var total = rate*item28;

document.getElementById(totalId).innerHTML = '£ '+total;

}[/QUOTE]
Copy linkTweet thisAlerts:
@KorJul 16.2008 — And how/where do you call that function? can we see the whole picture, please?
Copy linkTweet thisAlerts:
@Ay__351_eJul 16.2008 — calc(argument0, argument1,....argumentN)

calc([COLOR="Red"]argument0[/COLOR], [COLOR="Blue"]argument1[/COLOR], [COLOR="Yellow"]argument2[/COLOR],[COLOR="Purple"]argument3[/COLOR], [COLOR="Magenta"]argument4[/COLOR], [COLOR="Green"]argumentN[/COLOR])

calc([COLOR="Red"]'item'[/COLOR],[COLOR="Blue"]'rate'[/COLOR],[COLOR="Green"]'total[/COLOR]')

calc([COLOR="Red"]'item'[/COLOR],[COLOR="Blue"]'rate'[/COLOR][COLOR="Yellow"],'inp3'[/COLOR],[COLOR="Purple"]'inp4'[/COLOR],[COLOR="Magenta"]'inp5'[/COLOR],[COLOR="Green"]'total2'[/COLOR])
<br/>
&lt;script type="text/javascript"&gt;

function calc(){
var A=[];
// alert(arguments[0]);
// alert(arguments[1]);
// alert(arguments[2])
// alert(arguments[3]);
// alert(arguments[4]);
// alert(arguments[5])
// alert(arguments.length);
for(var i=0; i&lt;arguments.length-1; i++) {
var el=document.getElementById(arguments[i]);
A[A.length]=el.value;
}
//alert(A);
// alert(arguments[arguments.length-1])
var total= document.getElementById(arguments[arguments.length-1]);
var t = eval(A.join('*'));
// alert(t);
total.innerHTML = '&amp;#163; '+ t;
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;input type="text" id="item" value="2"&gt;&lt;br&gt;
&lt;input type="text" id="rate" value="3"&gt;&lt;br&gt;
&lt;input type="text" id="inp3" value="4"&gt;&lt;br&gt;
&lt;input type="text" id="inp4" value="5"&gt;&lt;br&gt;
&lt;input type="text" id="inp5" value="6"&gt;&lt;br&gt;
&lt;input type="button" value="click me" onclick="calc('item','rate','total')" &gt;&lt;span id="total"&gt;&lt;/span&gt;&lt;br&gt;
&lt;input type="button" value="click me" onclick="calc('item','rate','inp3','inp4','inp5','total2')" &gt;&lt;span id="total2"&gt;&lt;/span&gt;
×

Success!

Help @myanavrin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...