Verbat Posted February 27, 2008 Share Posted February 27, 2008 I have this script that i use for submit buttons - onclick="if(confirm(Are you sure?')) window.location.href='./test.php';" How can i make this onclick script work with an image instead of a submit button? Thanks Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 put the image inside of an 'a' tag, then add that onclick to the 'a' tag. Quote Link to comment Share on other sites More sharing options...
Verbat Posted February 27, 2008 Author Share Posted February 27, 2008 But if i put HREF inside it takes me to the link of the HREF and not the onclick. Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 So set the href of the a tag to be test.php. Then return the value of the confirm statement, so that if you click "no", it wont forward. Quote Link to comment Share on other sites More sharing options...
Verbat Posted February 27, 2008 Author Share Posted February 27, 2008 <a href="hotmail.com" onclick="if(confirm(Are you sure?')) window.location.href='gmail.com';">test</a></p> For example, no matter what i click it still goes to hotmail.com Instead on the TEST i put a picture but it doesnt matter. Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 <a href="gmail.com" onclick="return confirm(Are you sure?')">test</a> Quote Link to comment Share on other sites More sharing options...
Verbat Posted February 27, 2008 Author Share Posted February 27, 2008 It gives an error. Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 <a href="http://www.gmail.com" onclick="return confirm('Are you sure?')">test</a> Quote Link to comment Share on other sites More sharing options...
Verbat Posted February 28, 2008 Author Share Posted February 28, 2008 Thanks..... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.