Jump to content

how can i use an anchor to launch a snippit of javascript?


threeo

Recommended Posts

i have an existing menu that uses DIVs where each drop-down menu item is an anchor that references a page. what i'd LIKE to do....is have one of my drop-down items fire a javascript confirmation....asking the user if they are sure they want to leave the site.

i can get the anchor to fire the javascript just fine.....but it's the "href=" part that causes me problems. if the user clicks "no" (they don't want to leave the site....so....do nothing) they are getting redirected to some arbitrary page and i don't know why. i tried setting href="#" and href="" but get the same results.

my javascript just says "if confirmation=="yes" then window.location="newpage" else "" (nothing)

 

if i can't use an anchor.....is there a way to use a button but have it only show as plain text (don't want a button on my dropdown menu)

 

u dun really hafta use an anchor.. u could use javascript inside the href.. but if you want to use an anchor you'd use

 

onclick="" inside the <a> tag..

 

but if you want to do like js in the href u just do

 

<a href="javascript:code.to.do('when',CLICKED);">NO</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.