Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Differences in button behaviors


Message #1 by hugh@k... on Thu, 16 Jan 2003 02:53:22
Jeez Imar!  Too much time working with server controls - forgetting basic 
HTML.  As always, thanks for your help.  You advice is right on as usual.

> Hi Hugh,

AFAIK, <input type="image"> is an alternative for <input type="submit"> 
and 
NOT <input type="button">
So, when you click the image, the onclick fires AND the page gets 
submitted 
to the server, where apparently a calculation is made. You can see this 
from your browser's progress bar: you can actually see it retrieve a new 
page.

If you want to stop the image from submitting, try this:

     <input type="image" src="images/PrintThisPage.jpg" onclick="return 
printpage();">

(I added return to the onclick handler)

In your print function, add return false; :

     function printpage() {
         window.print();
         return false;
     }


If, on the other hand, you want the simple button to submit, change its 
type from "button" to "submit".

HtH

Imar


At 02:53 AM 1/16/2003 +0000, you wrote:
>Hello Everyone and thanks for your help in advance.  I have a .Net
>application that cna be seen at:
>
>http://www.hughmclaughlin.com/closeout.aspx
>
>You will note that there is a simple input button and another input
>button with an image.  Both buttons call the same function printpage()
>which opens the printer manager.  However, the page reacts differently
>with the two buttons.  The simple button causes no changes in the total
>field, but the one with the images also seems to fire the OnChange event
>and generate a total.  Why is the two different since the only difference
>I can see is the image?  Any feedback would be greatly appreciated.
>---



  Return to Index