pass more then 1 parameter in javascript.

Posted by Bhagwati under JavaScript on 7/4/2012 | Points: 10 | Views : 2784 | Status : [Member] | Replies : 6
hi,

I want to pass more then 1 parameter in javascript function.
how can i send more then 1 parameter.

Bhagwati pal


Responses

Posted by: Premalatha on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
If there is more than one argument to de specified then we separate them with commas. The arguments are then used within the function just as if they were variables but they are not, they are just substitute names for the variables that we will tell the function to use when we actually run it.
function writeSentence(argument1,argument2) {
document.write('The '+argument1+' is '+argument2+'.<br />');
}
Passing Values as Parameters

You don't have to define a variable to pass as a parameter to a function. You can pass values directly provided that the function is only going to use the value and is not expected to be able to change it.

As the "a" variable always contains "table" in our example above, we don't need to define this variable if we are only going to use the value in our function call. We can instead pass the value as the parameter instead of a variable containing the value.

We do it like this:

writeSentence('table',b);
You can pass any combination of variables and values as parameters to a function that does not update the value passed to it.

Premalatha
Software Engineer

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
If Your satisfied with this, please Mark As Answer

Premalatha
Software Engineer

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhagwati on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
i pass like
onclick=javascript:myFunction('id','name');
but it is not accepting the values in that function.
and the function is
myFunction(id,name){
alert(id);
alert(name);
}

Bhagwati pal

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhagwati on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
onclick='editIndustryVertical('10','12');'
it's saying incorrect syntax near -

if i am passing single value it's accepting.

Bhagwati pal

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu.Malik on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Use Javascript Method like this . This is Working

<script type="text/javascript">
function myFunction(id,name){
alert(id);
alert(name);
}
</script>

<input type="button" value="Click Me" onclick="javascript:myFunction('id','name');" />

Thanks & Regards ,
Anu Malik

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

yes Anu malik's Code is Working Correctly

Thanks

R D Patel

Bhagwati, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response