[Javascript] button?

Nick Fitzsimons nick at nickfitz.co.uk
Thu Jun 15 11:37:03 CDT 2006


tedd wrote:
> Hi:
> 
> Why does:
> 
>    <input type="button" value = "Upload" onclick="window.location='up.php' ">	
> 
> work, while:
> 
>    <button  onclick="window.location='up.php' ">Upload</button>
> 
> doesn't ?
> 
> What js could I use with <button> to do the same thing as above with <input type="button">?
> 

You don't say which browser you're having trouble with, but the <button> 
element has a "type" attribute; try adding type="button" and see if that 
helps. Also, you might want to add "return false;" to cancel any default 
action (shouldn't matter with type="button" though), and it's usually 
recommended to set "window.location.href" - well, recommended by purists 
like me :-)

<button type="button" onclick="window.location.href='up.php'; return 
false;">Upload</button>

HTH,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list