?
Solved

return a javascript variable to a ahref

Posted on 2003-12-03
7
Medium Priority
?
570 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
Suggested Courses

864 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