Forum Moderators: open

Message Too Old, No Replies

Event Handler and Netscape 4.x

Image type does not support event handler?

         

tesla

7:19 am on Aug 19, 2002 (gmt 0)

10+ Year Member




It appears that Netscape 4.x does not support event handlers with the input type "image", as below.

<input type="image" src="image.gif" onClick="alert('Thanks! ')">

This works fine for Netscape 6.2 and IE, but there is no reaction from Netscape 4.7. Is there a simple work around for this??

Thanks,

starway

9:11 am on Aug 19, 2002 (gmt 0)

10+ Year Member



No. <input type="image"> should be used only as a perlacement for Submit form button (<input type="submit").

If you want to use image to activate some script action, use a simple image link:
<a href="#" onclick="alert('Thanks! ')"><img src="" ... border="0"></a>

rewboss

12:32 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



I think tesla is aware of what type="image" is used for, and it is a curious omission on the part of NS4 -- but then, NS4 is known for curious omissions.

I don't think popping up an alert when the form is submitted is a good idea, since if the form is submitted to a CGI app or other server-side script you should get a confirmation screen back anyway, and that should say "Thanks". A JavaScript alert is just something else to click on, and it's modal, meaning the form won't be submitted until the OK button is pressed. That just wastes time.

However, the workaround is simple: use the onsubmit handler of the form element. So your <form> tag should look like this:

<form onsubmit="alert('Thanks'); return true;" action="...">

This will work even if the user submits the form without hitting the submit button (for example, by hitting the Enter key).

Notice I have included return true in the event handler. Strictly speaking this is unnecesary, but hints at what this handler is actually for: if you return false, the form will not be submitted. This is what is happening when you have a form validation script:

<form onsubmit="return check(this);" action="...">

This will pass the form to a function called check() which you must write yourself. You arrange things so that check() returns false if the form contains errors, true if it is error-free and can be submitted.

tesla

2:30 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



Rewboss,

That is the fix I'm looking for. The reason I use the Alert as such, is that it is part of a "Add to Cart" button. When a customer presses it, it runs a ASP script that adds the item to their cart. It then returns to the same page. You could display a message on the same page, but customers tend to miss the text within all the other text on that page. So, the pop-up solves this problem by focusing attention. I could return to a page that just has the message indicating the item was added to the cart, but then naviagation becomes more difficult, as back would need to be clicked "twice" instead of once to return to the page prior to the product page.

Thanks,

rewboss

7:25 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



Well, the problem is that the onsubmit handler is fired before the form is actually submitted. What happens if there's some error and the item isn't added to my cart?

Also, depending on what it is you're actually selling, you have to bear in mind that constantly getting popup alerts and having to bat them down (that's what it feels like) is intensely annoying. The reason they are called "alerts" is because they are designed to alert the user of some critical problem. Hence the exclamation mark and the loud Bong! noise you get.