Solved

return a javascript variable to a ahref

Posted on 2003-12-03
7
555 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
Comment Utility

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

Expert Comment

by:Michel Plungjan
Comment Utility
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
Comment Utility
<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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 75

Expert Comment

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

Expert Comment

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

Author Comment

by:esbesb
Comment Utility
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
Comment Utility
YW :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now