ASP help. Setting variables within an <a> tag

This is a discussion on ASP help. Setting variables within an <a> tag within the Tech Board forums, part of the Community Boards category; OK, here's the thing. I have a variable named sTXT that I need to be able to set using a ...

  1. #1
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536

    ASP help. Setting variables within an <a> tag

    OK, here's the thing. I have a variable named sTXT that I need to be able to set using a standard <a href> tag. The user should be able to click the link, and the sTXT variable will be changed to whatever value I have hard coded in for that link.

    For example, if I have a section of links such as: Washington, Oregon, California, etc... then when the user hits that "Washington" link, sTXT is set to the value "Washington" and the page stays at the current page.

    I've tried <a href="javascript:void(0)"; onClick='<% sTXT = "Washingon" %>' >Washington</a>, as well as a few variations of that.

    And what happens is it seems to ignore the "onClick" and just automatically sets the value, regardless of whether it was clicked or not. I'm generally just having problems with the onClick...

    I've tried making a button, just to test, with and onClick that goes is set to call a sub call, but it never works! I hit the button, and nothing happens. I know the sub call works though, because I can call it outside of the button and it works just fine

    If anybody could help that would be awesome. I've tried looking at other more ASP based forums, but most questions go unanswered...

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <SCRIPT LANGUAGE="Javascript">
    function Hello(strCity)
    {
    	alert("City = " + strCity);
    }
    </SCRIPT>
    </HEAD>
    
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
    <A href=""; onClick="Hello('Washinton')">Washington</A>
    <BR>
    <A href=""; onClick="Hello('California')">California</A>
    <BR>
    <A href=""; onClick="Hello('New York')">New York</A>
    </BODY>
    </HTML>

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    About Fordy's code, don't forget to hide your script from old browsers by <!-- and //--> your code.

  4. #4
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536
    That's great and all (and thanks for the reply)... but this is ASP, that's javascript. It needs to be more along the lines of the: onClick='<% sTXT = "Washingon" %>' with the block script

    I'm having a heck of a time getting this thing to work, but thanks for the reply anyway!

    OH, p.s., I realize it's sets it inside of a function, which is damn near exactly what I want to do, but for whatever reason the code is ignoring the "onClick" and just doing what's inside of there, so if I have it call a function, it does it regardless of whether you click the link or not such as if I had onClick='<%call subfunction%>' it would either call the subfunction even if I didn't click it, or more often then not, just give me an error and do absolutely nothing when I click it

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    ASP is processed before the page even gets sent back to the browser. You'd have to use VBScript or JavaScript to do what you want to do.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536
    That's kinda what I expected to hear... If I do <language="vbscript" runat="server"> do you know if that will work? Basically, I'd like to avoid putting the source on the client side as much as possible, I only want them to see the output.

    I'm modifying a pre-existing web page, and the way it was written is absolutely great for it's purpose, but now it needs a new purpose and this is being a real pain...

  7. #7
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536
    Thanks for the tip Fordy/XSquared. A quick little 2 line javascript function did the trick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Setting variables to clipboard values?
    By jonnyfb in forum Windows Programming
    Replies: 4
    Last Post: 03-19-2006, 10:03 AM
  2. Setting environment variables.
    By Ezzetabi in forum C++ Programming
    Replies: 10
    Last Post: 07-26-2005, 08:30 AM
  3. Replies: 6
    Last Post: 01-02-2004, 12:01 PM
  4. Setting OS Environment Variables
    By ImNotMad in forum C Programming
    Replies: 4
    Last Post: 10-23-2003, 02:07 AM
  5. Having trouble correctly setting DJGPP's env. variables in XP
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 06-05-2002, 10:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21