?
Solved

How to call a function inside another function?

Posted on 2009-03-28
5
Medium Priority
?
1,460 Views
Last Modified: 2012-05-06
Is it possible to call another function inside another one when using it in an href? See below.
My second function "getJulianDate()" just prints the name out (ie.. "getJulianDate()".
<a href="javascript:popItem(4,getJulianDate());">Test Link</a>

Open in new window

0
Comment
Question by:greddin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 30

Assisted Solution

by:third
third earned 400 total points
ID: 24012460
it should work fine. see sample below.

though i suggest you use this format (i.e. use onclick and always return false so href will not be executed.)

<a href="#" onclick="popItem(4,getJulianDate());return false;">Recommended Test Link</a>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Third Santor</title>
<script>
function getJulianDate(){
  return 'julian';
}
 
function popItem(num, str){
  alert(str);
}
</script>
</head>
<body>
<a href="javascript:popItem(4,getJulianDate());">Test Link</a><br /><br />
 
 
<a href="#" onclick="popItem(4,getJulianDate());return false;">Recommended Test Link</a>
</body>
</html>

Open in new window

0
 
LVL 15

Expert Comment

by:fsze88
ID: 24012795
try using eval function may be better
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Third Santor</title>
<script>
function getJulianDate(){
  return 'julian';
}
 
function popItem(num, str){
  eval(str);
}
 
function getJulianDate2(){
  alert('do somethings here');
}
 
</script>
</head>
<body>
<a href="javascript:popItem(4,'getJulianDate2()');">Test Link</a><br /><br />
 
 
<a href="#" onclick="popItem(4,'getJulianDate2()');return false;">Recommended Test Link</a>
</body>
</html>

Open in new window

0
 
LVL 15

Accepted Solution

by:
fsze88 earned 1600 total points
ID: 24012926
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Third Santor</title>
<script>
function getJulianDate(){
  return 'julian';
}
 
function popItem(num, str){
  var returnvar;
  eval('returnvar = ' + str);
  alert(returnvar);
}

function getJulianDate2(){
//  alert('do somethings here');
  return 'abc';
}

</script>
</head>
<body>
<a href="javascript:popItem(4,'getJulianDate2()');">Test Link</a><br /><br />
 
 
<a href="#" onclick="popItem(4,'getJulianDate2()');return false;">Recommended Test Link</a>
</body>
</html>
0
 

Author Closing Comment

by:greddin
ID: 31563978
Thanks for your expert help!
0
 
LVL 30

Expert Comment

by:third
ID: 24015153
Welcome. Using eval on this case though is no way better.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question