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

input type image 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Ok... I have a page... it has a button...
Code:
<input type=&quot;button&quot; value=&quot;View List&quot; ... onClick='window.open(&quot;newpage&quot;, &quot;blahblah&quot;, &quot;height=600,etc&quot;)' />

It happens to sit within a form, there's nothing I can do about that.

It's great... works nicely... however, I decided it just didn't look right, the text took up too much room. so I swapped it to an image type instead of a button type, added a source... and walah that worked too... except that clicking the image would always submit the form as well... which is bad. Anyone know any workarounds for this?

Behavior same in IE6 and Firebird .7+

Thanks,
Rob
 
the only button that can have an image is submit (as far as i know) any other button you want as an image will require javascript -- or or google might lead you to a script that will do this.

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
skiflyer,

This is an easy one, just use an image:

<img src=&quot;image_name.gif&quot; onClick='window.open(&quot;newpage&quot;, &quot;blahblah&quot;, &quot;height=600,etc&quot;)'>

or if you want to still use a form element:

<input type=&quot;image&quot; src=&quot;image_name.gif&quot; name=&quot;name&quot; value=&quot;value&quot; onClick='window.open(&quot;newpage&quot;, &quot;blahblah&quot;, &quot;height=600,etc&quot;) return false'>

Hope this helps!

NATE


mainframe.gif


Got a question? Search G O O G L E for links to the fastest answers: www.google.com
 
Nate offered two good solutions... here is another!

Code:
<input type=&quot;button&quot; value=&quot;View List&quot; ... onClick='myWin=window.open(&quot;newpage&quot;, &quot;blahblah&quot;, &quot;height=600,etc&quot;)' />

The window.open() method returns true or false. If it returns true then it it's like pressing the submit button on the form.... but if you assign the result to a variable (I used myWin) then there is no such side-effect.

Nate did much the same by specifically returning false in the onClick.

All the best
Jeff
 
Thank you all... I went with spyderix's solution of &quot;return false&quot; at the end... it may seem silly, but the reason I'm not a fan of the
Code:
<img src...onclick>
is because you lose things like the hand icon on hover, and while this can be replaced with CSS, I just don't prefer it. however, this return false option took care of that.

Thanks much.

-Rob (looks like BabyJeffy's response would've accomplished all of my goals as well... but the return false was just more transparent to me, and on code I may not always maintain I consider that important)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top