Link to home
Start Free TrialLog in
Avatar of bkeithm
bkeithm

asked on

Anchor tag question

I have a form with two input fields and 5 anchored GIFs for buttons.  Each GIF will send me to a different URL.  I want to transfer the data within the fields in the first screen to the new URL when I press the GIF button.  How can I accomplish this?
Avatar of knightEknight
knightEknight
Flag of United States of America image

Try this:

<A href='#' onClick='document.myform.action="URL1.htm";document.myform.submit();return(false);'><IMG src='img1.gif' border='0'></a>

<A href='#' onClick='document.myform.action="URL2.htm";document.myform.submit();return(false);'><IMG src='img2.gif' border='0'></a>

<A href='#' onClick='document.myform.action="URL3.htm";document.myform.submit();return(false);'><IMG src='img3.gif' border='0'></a>

etc

____________________________________________________________________________________________________________________________________
even better than <a href="#"...> would be to use <a href="javascript:void()"...> because it won't jump to the top of the page when you click it...
... that is why I return false in the onClick -- so that it won't jump.  Therefore, '#' is no worse than 'javascript:void();'  or even 'javascript:;'
I did not know that! You learn something new everyday, huh? Thanks for the new knowledge, knightEknight  =)
Yep!  That is the purpose of returning true or false from an anchor.  You could even use href='cnn.com' and as long as you return false, you will never actually go to cnn.com .  It also allows you to do things like this:

<A href='www.cnn.com' onClick='return(confirm("Are you sure?"));'>Click Me!</a>
Avatar of bkeithm
bkeithm

ASKER

Thanks knightEknight.  The points are yours. Sorry about the tardiness of the acceptance.  I've been out-ot-pocket for a few days.  
Glad to help!
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial