Link to home
Start Free TrialLog in
Avatar of greddin
greddinFlag for United States of America

asked on

How to call a function inside another function?

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

SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kin Fat SZE
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greddin

ASKER

Thanks for your expert help!
Welcome. Using eval on this case though is no way better.