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

Non-submit button inside form?

Status
Not open for further replies.

cmayo

MIS
Apr 23, 2001
159
US
This is driving me batty and I simply cannot find a workaround...

I need a button inside a form which call a Javascript function to confirm the user's choice, then redirect the browser page. Ideally I'd like am IMAGE button but at this point, I'd take just about anything.

Since the redirect seems to be the issue and calling it directly from the button produces the same result, I've simplified the problem to the example below:

<form>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=22 align= align="center"><input type="checkbox"></td>
<td width=22 align= align="center">
<input type="image"
name="delete"
src=" onClick="javascript:window.location='http:\\ - no redirect.</td>
</tr>
</table>
</form>

The example is currently running at
I have tried this using both a standard INPUT TYPE="button" and a text link with an onClick action and both those methods almost work, but append the redirect URL to the server's root url, i.e.
Would appreciate any help with this!
 
Try changing you instances of double back-slashes (\\) to double forward-slashes (//). I think you're suffering from an accidental escape of a slash.

--Dave
 
Ah, good catch LookingForInfo, thanks. Sometimes you just look at this stuff for too long.

The INPUT TYPE="button" now works... can anyone tell me where I'm going wrong on the IMAGE button, or is there simply no way to make an image button within a form NOT be a submit button?
 
Two things you can try are to NOT use form tags (then image won't submit) or adding onsubmit='return false' to your form tag. The redirect should (maybe?) work then.

--Dave
 
>[tt]<input type="image"
name="delete" src=" onClick="javascript:window.location='http:\\www.google.com'">[/tt]
Change this to.
[tt]<input type="image"
name="delete"
src=" onClick="[green]javascript:[/green]window.location='http:\\www.google.com';[red]return false[/red];">[/tt]
You can spare the javascript: pseudo protocol thing, but it us up to you.
 
I would opt for the "return false" over omitting the form tags... Some versions of NN have issues with form elements that do are not inside a form, I believe.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks all, very much. Tsuji's "return false" turned the trick and things are working just the way I wanted.

I really appreciate all the tips,

Chuck Mayo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top