Link to home
Start Free TrialLog in
Avatar of esbesb
esbesb

asked on

return a javascript variable to a ahref

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
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>

<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???
@gam3r: And exactly where do you post the added information that I did not already post?
But good point anyway... which is why I use noscript
Avatar of esbesb
esbesb

ASKER

Fantastic mplungjan - Had intended to test if Javascript remained Javascript=
but this is far far better and avoids hidden fields - many many thanks