Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a value to an onclick event

Status
Not open for further replies.

nareshreporter

Programmer
Mar 3, 2005
13
0
0
US
Hi,
I have an external javascript function that returns a value. But im calling this function when ever user clicks a button (onclick event). How do i access that value in my html page.

EXAMPLE:

IN HTML:
<input type="button" name="btn" onclick="addNumbers(var1, var2)"

IN .JS FILE:
function addNumbers(num1, num2)
{
return num1 + num2;
}

Now how do i access this value in HTML page.

I appreciate if anyone could help me out.
Thanks in advance
 

Assuming you mean access the return value of the function, there are two ways:

1. Save it in a JS variable, and then access that variable, or

2. Call the function only when you need the result, and use the result directly.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top