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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an image as a submit button works in IE, not NS 1

Status
Not open for further replies.

bgreenhouse

Technical User
Feb 20, 2000
231
CA
Hi Folks

I'm not sure if this is a JavaScript issue or an HTML issue, but I thought I'd ask here anyway...I am using the following code:

<a onMouseOut=&quot;swapImgRestore()&quot; onMouseOver=&quot;swapimage('begin_button','','images/begin_button_over.gif',1)&quot; onClick=&quot;validate()&quot;>
<img src=&quot;images/begin_button.gif&quot; width=&quot;144&quot; height=&quot;28&quot; name=&quot;begin_button&quot; border=&quot;0&quot; align=&quot;middle&quot; alt=&quot;Click Here to Begin&quot;></a>

With the validate function:

function validate() {
if (document.login.card_num.value ==&quot;&quot;)
{
alert(&quot;Please input your card number.&quot;);
return;
}
else if (document.login.pin_num.value ==&quot;&quot;)
{
alert(&quot;Please input your PIN number.&quot;);
return;
}
document.login.submit();
location=&quot;intro.htm&quot;;
}

This works well in IE, but Netscape doesn't seem to like it (I can't even click on the image).


I'm just beginning with javascript, so excuse me if there is some really garbled coding...I know too that I could use <input type=image> instead of using the .submit, but I don't know if that would fix the problem, and I'd like to understand what's causing the problems here.

Thanks for anyhelp!

Ben
[sig][/sig]
 
Hi Ben,

you should put the onMouseOut and onMouseOver event in the <IMG> tag, and you should have &quot;href=&quot; inside your <A> tag..

please try this..

<A href=&quot;javascript:validate()&quot;>
<img src=&quot;images/begin_button.gif&quot;
width=&quot;144&quot; height=&quot;28&quot;
name=&quot;begin_button&quot; border=&quot;0&quot;
align=&quot;middle&quot; alt=&quot;Click Here to Begin&quot;
onMouseOver=&quot;....&quot; onMouseOut=&quot;....&quot;
></a>

hope this help,
[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
Netscape doesn't expose an onclick event for an image. Therefore, your validate function will never be called for Netscape users. This is one of the many things that causes cross-browser problems. Some alternate solutions have been suggested here. Do some searches and I'm sure you'll find them. [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>[/sig]
 
nick bulka,

Actually, netscape Does support onclick event for an image <IMG>, but not for a input type image <INPUT type=Image>
[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
Chiu,
I should have looked more closely at the code. The onclick handler is being declared for the link, not the image, so the validate function will get called. I still stand by my statement about images not generating an onclick in Netscape, though. [sig]<p>nick bulka<br><a href=mailto: > </a><br>[/sig]
 
Nick

I have to say that Chiu's code (which calls an onclick event in an image) works in both IE and NS 4.05. Now the rollovers aren't working though...I'll try and get that on my own though. Thanks for your help guys!

Ben [sig][/sig]
 
nick bulka,

You are right, the OnClick event doesn't work for Netscape.
[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top