473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

javascript function arguments

184 100+
Hi all,
one doubt in javascript...

[HTML]
<script>
function samFunc(param1,param2,param3,param4,param5)
{
var value1=param1;
var value2=param2;
var value3=param3;
var value4=param4;
var value5=param5;
var Total= parseInt(value1)+parseInt(value2)+parseInt(value3) +parseInt(value4)+parseInt(value5);
}

</script>

<body>
<input type="button" name="submit" value="submit" onclick="samFunc('1','2','3','4','5')">
[/HTML]
In the above program,is there anyway to get "param value" in "for loop"
something like...

Expand|Select|Wrap|Line Numbers
  1. var value=0;
  2. for(i=1;i<6;i++)
  3.   {
  4.      value=parseInt(value)+parseInt(param+<%=i%>);
  5. }
Is there any way to get all values in sin gle statement???



-Thanks & Regards
Hamsa
Aug 30 '07 #1
3 1424
dmjpro
2,476 2GB
Hi all,
one doubt in javascript...
[code=html]
<script>
function samFunc(param1,param2,param3,param4,param5)
{
var value1=param1;
var value2=param2;
var value3=param3;
var value4=param4;
var value5=param5;
var Total= parseInt(value1)+parseInt(value2)+parseInt(value3) +parseInt(value4)+parseInt(value5);
}

</script>
<body>
<input type="button" name="submit" value="submit" onclick="samFunc('1','2','3','4','5')">
[code]

In the above program,is there anyway to get "param value" in "for loop"
something like...
Expand|Select|Wrap|Line Numbers
  1. var value=0;
  2. for(i=1;i<6;i++)
  3.   {
  4.      value=parseInt(value)+parseInt(param+<%=i%>);
  5. }
  6.  
Is there any way to get all values in sin gle statement???



-Thanks & Regards
Hamsa

Why you didn't follow the Post Guidelines?
First of all this is not allowed in JavaScript.
It is valid in JSP.
You can do this using Java Script.

Expand|Select|Wrap|Line Numbers
  1. function samFunc()
  2.    {
  3.       var Total= 0;
  4.    for(var i=0;i<arguments.length;i++)
  5.    Total+=parseInt(arguments[i]);
  6.       }
  7.  
I think it will work fine.
Best of Luck with your Try.

Kind regards,
Dmjpro.
Aug 30 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

please use code-tags when posting code ...

we may do some cool things to do that ... we 'press' the arguments to an array and may iterate through it then ;)

Expand|Select|Wrap|Line Numbers
  1. var value  = 0;
  2. var params = Array.apply(this, arguments);
  3.  
  4. for(var i in params) {
  5.     value += parseInt(params[i]);
  6. }
  7.  
kind regards

ps: the above code provided by dmjpro is working too of course :) and perhaps better to understand
Aug 30 '07 #3
gaya3
184 100+
Why you didn't follow the Post Guidelines?
First of all this is not allowed in JavaScript.
It is valid in JSP.
You can do this using Java Script.

Expand|Select|Wrap|Line Numbers
  1. function samFunc()
  2.    {
  3.       var Total= 0;
  4.    for(var i=0;i<arguments.length;i++)
  5.    Total+=parseInt(arguments[i]);
  6.       }
  7.  
I think it will work fine.
Best of Luck with your Try.

Kind regards,
Dmjpro.


Hi dmjpro,
Thank u... its working fine...:-)
Aug 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Derek Richards | last post by:
In VbScript, when you have a method, you do ..Method A, B, C, D. If you would take some default values, you do ..Method A,,,D My question is that how you can do this in JavaScript ..Method(???)...
2
by: John J | last post by:
Hi there I have the following code on a site that works as it should but I'd like to understand how it works (a luxury I realise :). I use it to change the colour of buttons on a menu when a...
2
by: James Leech | last post by:
Reposted due to no response. Hi guys I am using Dreamweaver to create an intranet site that is to be accessed by a PDA, but I have hit a problem with JavaScript under Pocket Internet...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
13
by: Walton | last post by:
I'm wondering if anyone knows or knows where to find a collection of javascript "brain teasers" for lack of a better description. Companies use these types of tests for programmers all the time...
10
by: Evan Charlton | last post by:
Hey all, I'm having some trouble with window.setInterval() within a custom object/prototype. Here is my code: function MyClass() { // do some junk // ... // define methods this.m_one =...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.