Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

return a javascript variable to a ahref

Posted on 2003-12-03
7
Medium Priority
?
568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

618 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