how to assign a Jscript function return value to a TAG attribut?

  • Thread starter Thread starter José Joye
  • Start date Start date
J

José Joye

Hello,

I'm having problem to give to the src attribut of the <img> tag an jscript
function as value.
What is the correct syntax?
With my syntax the jscript function is executed. However, the function
return value is not assigned to the src attribut

Thanks,
José

My snippet:
========
<html>

<head>
<script>
<!--
function F_getImageName()
{
return "./images/about_up_on.gif"
}
//-->
</script>

</head>
<body>
<a href="../Newsletter.htm">
<img ID="NavButton2" name="NavButton2" height="24" width="100"
src="javascript:F_getImageName()"
<<<<<<---------------------- here !!!!
border="0" alt="Letter1">
</a>
</body>
</html>
 
Hi,

You have to set the src attribute.

Try this instead:

<script language="javascript" >
function myFunc(sName)
{
document.images[sName].src = "images/upslogo.gif";
return true;
}
</script>
</head>

<body>
<a href="http://www.websunlimited.com"><img id=img1 src="javascript:myFunc('img1');" ></a>
</body>

--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
J-Bots Plus 2002 87 components for FrontPage
http://www.websunlimited.com/order/Product/JBP2002/jbp_help_dir.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
 
I would write this as:
<body>
<script language="JavaScript" type="text/javascript"><!--
var d=document, loc;
loc=F_getImageName();
d.write('<a href="../Newsletter.htm">');
d.write('<img ID="Navbutton2" name="Navbutton2" height="24"');
d.write(' width="100" src="' + loc + '" border="0" alt="Letter1">');
d.write('</a>');
//-->
</script>

The entire link is written in JavaScript so that any users with JavaScript
turned off will not get any errors.
 
Ronx,

No errors will be presented to the visitor. Instead they will see an image placeholder with a broken image. In your implementation
the design elements will not be present at all. Possibly throwing the design off and removing a navigational link for sure.

Also, if you're concerned with JavaScript being turned off then do a functional test to see if it is and alert the visitor that it
is required or transfer to a different presentation.

IMHO


--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Wish you could calculate form field totals? Well, you can with Form Caculator
http://www.websunlimited.com/order/Product/FormCalc/formcalc.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
 
Thanks al lot!!!
I think I'a slowly getting the point with dynamic HTML ... ;-)

José
MD Websunlimited said:
Hi,

You have to set the src attribute.

Try this instead:

<script language="javascript" >
function myFunc(sName)
{
document.images[sName].src = "images/upslogo.gif";
return true;
}
</script>
</head>

<body>
<a href="http://www.websunlimited.com"><img id=img1
 
Back
Top