Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use Javascript to display selected hyperlink

    I'm not that familiar with classic ASP or Javascript but need to change an exisiting program to do the following:

    Add a link to a page but only for certain marketers.

    I have a classic ASP page that has a couple of hyperlinks for each marketer that is selected from a combobox drop down. The new hyperlink is to be added but only for select marketers. The rest don't even get to see this new hyperlink.

    I added a function in Javascript as such:

    Code:
    function IsPikeESCO(UID,UCD) 
    {
    	var strTemp;
    	var mktrno,mktname;
    	var frm;
    	var IsPike;
    
    	IsPike = false;
    	
    	frm = document.Downloads;
    
    	strTemp=frm.MKTRACCT.options[frm.MKTRACCT.selectedIndex].text;
    	mktrno=strTemp.substring(0,10);
    
    	switch (mktrno)
    	{
    		case 8:		
    			IsPike = True;				
    			break;
    	
    		case 99:
    			IsPike = True;
    			break;
    		
    		case 162:
    			IsPike = True;
    			break;
    	}
    	
    	return IsPike;
    
    }
    Now I need to check if True then display the hyperlink, so I came up with this, which I know is not correct:

    Code:
    <tr><td></td><td
    <%IF <a HREF="javascript:IsPikeESCO('<%response.write request("passUID")%>','<%response.write request("passUCD")%>')" = True THEN%>
    			onMouseOver="/orradata/pike.DAT">Pike Data</font></a>
    <%END IF%>
    I want to be able to check the fuction for each marketer and if return is TRUE, then produce the hyperlink which will open a data file if clicked.

    Can someone help? I'm not sure how to use the <%IF statement in conjunction with a javascript function that checks for a return value, and based on that return value, does some action.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    One thing I see right away:
    Code:
    	mktrno=strTemp.substring(0,10)
    	switch (mktrno)
    	{
    		case 8:
    Since your case values are numbers, you should ensure that indeed mktrno is also a number.

    Maybe we can rewrite that code to be simpler, too?
    Code:
    function IsPikeESCO(UID,UCD) 
    {
            var mktracct = document.downloads.MKTRACCT;
    	var strTemp = mktracct.options[ nutracct.selectedIndex ].text;
    
            switch( Number( strTemp.substring(0,10) )
            {
    		case 8:		
    		case 99:
    		case 162:
    			return true;
    	}
            return false;
    }

    And then I *think* this is what you are asking for:
    Code:
    <tr>
        <td></td>
        <td>
            <a href="/orradata/pike.DAT" style="...put font info here ..."
                 onclick="return IsPikeESCO('<%=request("passUID")%>','<%=request("passUCD")%>');" 
            >Pike Data</a>
        </td>
    The <font> tag is obsolete. Just use a style= (or class=) in the <a> tag to specify the appearance of "Pike Data".

    You see how that works? If the IsPikeESCO function returns true, the onclick returns true, and the hyperlink works. If the function returns false, the onclick returns false, and the hyperlink is not invoked.

    *************

    Not to ask a silly question, but...

    Why do you pass the two parameters, (UID,UCD), to the function and then never use them in the function?

    If you aren't going to use them, then you don't need to get them from the ASP code.
    Last edited by Old Pedant; 03-23-2012 at 09:45 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •