Solved

return a javascript variable to a ahref

Posted on 2003-12-03
7
559 Views
Last Modified: 2011-09-20
Hi
In order to check whether a user has javascript enabled on each page LOAD - I need a way of feeding a javascript variable into a ahref (becasue the links avoid posting form variables and a session variable on javascript needs to be updated on every page)

Heres  thef unction
function JSTrueOrFalse()
{
   indicatejavascript();
   var JStester;
   if (document.frmSearch.textJavascript.value == "JS is on")
    {
          JStester = "ON";
          alert("it's on");
          return JStester;
    }
    else
    {
         JStester = "OFF";
         alert("it's off");
         return JStester;
     }
}

Can you feed into a ref like
<a href="ProcessMeetingRequests.cfm?Javascript=" & return JSTester();>testing</a>

(doesn't work of course)
This is probably not possible - mixing server side and client side but has anyone invented a solution to this problem of testing javascript on page loads for links?

Thanks
0
Comment
Question by:esbesb
  • 5
7 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 9865644

<a href="ProcessMeetingRequests.cfm?Javascript=OFF"
onClick="this.href=this.href.replace('OFF','ON')">testing</a>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9865658
The onclick is only happening if javascript is on.
No need to test a hidden field.

If you insist on your field, try this


<a href="ProcessMeetingRequests.cfm?Javascript=OFF"
onClick="this.href=this.href.replace('OFF',JSTrueOrFalse())">testing</a>

or
<script>
document.write('<a href="ProcessMeetingRequests.cfm?Javascript=ON">testing</a>')
</script>
<noscript>
<a href="ProcessMeetingRequests.cfm?Javascript=OFF">testing</a>
</noscript>

0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 9866216
<script>
document.write('<a href="ProcessMeetingRequests.cfm?Javascript=' + JSTrueOrFalse());
</script>

maybe...? or have it like...

<a href="ProcessMeetingRequests.cfm?Javascript=OFF" onClick="window.location.href='ProcessMeetingRequests.cfm?Javascript=ON'">testing</a>

since event handlers won't work without JavaScript.

btw, how would you make this...

function JSTrueOrFalse()
{
   indicatejavascript();
   var JStester;
   if (document.frmSearch.textJavascript.value == "JS is on")
    {
          JStester = "ON";
          alert("it's on");
          return JStester;
    }
    else
    {
         JStester = "OFF";
         alert("it's off");
         return JStester;
     }
}

function work if JavaScript is not enabled on the system?????? how'd the page see it has JS if it would use JS to check...??? using a function to return a value???
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9867257
@gam3r: And exactly where do you post the added information that I did not already post?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9867269
But good point anyway... which is why I use noscript
0
 

Author Comment

by:esbesb
ID: 9869915
Fantastic mplungjan - Had intended to test if Javascript remained Javascript=
but this is far far better and avoids hidden fields - many many thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9870682
YW :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question