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)

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.