?
Solved

trying to detect js via form

Posted on 2011-03-01
20
Medium Priority
?
838 Views
Last Modified: 2013-12-24
on the top of a page I have a hidden form to detect js but it doesn't seem to be giving the value yes when js is on.

any ideas?
<script>
	function runDetectection() {
		document.getElementById('isJsEnabled').value = "yes"; 
	}
</script>
<body onLoad="runDetectection();">
<cfparam name="isJsEnabled" default="no">
<cfparam name="form.isJsEnabled" default="no">

<form name="testjs" action="boo" method="post">
<input type="Hidden" name="isJsEnabled" id="isJsEnabled" value"no"/>
</FORM>

Open in new window

0
Comment
Question by:Shawn
[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
  • 11
  • 8
20 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35011890
The overall logic is fine. How is the form being submitted? I'm assuming the hidden field is part of a bigger form that gets submitted .. ?
0
 
LVL 1

Author Comment

by:Shawn
ID: 35011932
the thing is the actual form is not being submitted. The user just clicks on a link to log in. If he/she has opted to have the password remembered the login form is bypassed.

I may not need the little form. I just need to set js as being enabled or not.
0
 
LVL 2

Expert Comment

by:dlewis9
ID: 35012107
Your code will set the value of the hidden form variable, but it can't be used in ColdFusion from the same page (the CF stuff has already executed server side, and JS is client side)..

You could do this script on a page with a submit button, and then on the action page read the form value and decide if the user can continue or needs to be redirected to tell them to have JS turned on.

Here's someone else who did that:
http://www.webmasterkb.com/Uwe/Forum.aspx/coldfusion-advanced/5189/Detect-javascript-enabled
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 52

Expert Comment

by:_agx_
ID: 35012113
The form  (or something similar) has to be submitted to the server ... or you won't be able to check the value.
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012163
what about in the link rather than a form?? is that possible?

<a href="#script_name#?action=affiliate.afflogin">Login</a>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 35012171
You could do the same thing with a link. Just use javascript to add a parameter to it on page load

<!--- test.cfm --->
<script type="text/javascript">
      function changeLink() {
            var elem = document.getElementById('loginLink');
            elem.href = elem.href +"?isJsEnabled=true";
      }
</script>

<body onLoad="changeLink()">
      <a href="login.cfm" id="loginLink">Login</a>
</body>

<!--- login.cfm --->
<cfparam name="url.isJsEnabled" default="false">
<cfdump var="#url#">
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012202
Our posts clashed.

If your link already has parameters then use "&" to append another one instead of "?"

      function changeLink() {
            var elem = document.getElementById('loginLink');
            var sep  = (elem.href.indexOf("?") >= 0 ? "&" : "?");
            elem.href = elem.href + sep +"isJsEnabled=true";
      }
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012241
i think I'm missing something. ere's what I have:

<script type="text/javascript">
      function changeLink() {
            var elem = document.getElementById('loginLink');
            var sep  = (elem.href.indexOf("?") >= 0 ? "&" : "?");
            elem.href = elem.href + sep +"isJsEnabled=true";
      }
</script>

<cfoutput>
<body onLoad="changeLink()">  
        <p><a href="#script_name#?action=affiliate.afflogin" id="loginLink">Login</a></p>
</body>  
</cfoutput>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012305
What you have works fine for me on a test page.  What's it NOT doing for you?

Results when javascript is disabled:
struct
ISJSENABLED       false
action       affiliate.afflogin

... results when javascript IS enabled:
struct
action       affiliate.afflogin
isJsEnabled       true
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012319
Btw: My test action page is just:

    <cfparam name="url.isJsEnabled" default="false">
     <cfdump var="#url#">
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012348
i am gettin
ISJSENABLED       false
action       affiliate.afflogin

whether it is on or not.

When I hover over the link I do not see the added part in the url. shouldn't I?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012365
Yeah, you should.  Are you running the exact code posted? Because it works fine in both FF and IE8.  Which suggests you're doing something different ;-)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012373
Also make sure you refresh the page after re-enabling/disabling javascript.
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012376
this is in a template inside another page. I'm pretty sure there is already a body element. would that make a difference?
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012407
my exact code...

dsp page:
<script type="text/javascript">
      function changeLink() {
            var elem = document.getElementById('loginLink');
            var sep  = (elem.href.indexOf("?") >= 0 ? "&" : "?");
            elem.href = elem.href + sep +"isJsEnabled=true";
      }
</script>

<cfoutput>
<body onLoad="changeLink()">  
        <p><a href="#script_name#?action=affiliate.afflogin" id="loginLink">Login</a></p>
</body>  
</cfoutput>

action page:
<cfparam name="url.isJsEnabled" default="false">
<cfdump var="#url#">
<cfabort>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012433
Nope. Works perfectly.  

Are you using url re-writing or routing pages through some handler or framework?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012450
this is in a template inside another page. I'm pretty sure there is already a body element. would that make a difference?

Yes ... I imagine only one body tag fires: the first one.  To test it, add an alert to your function and you'll probably see it's not firing
    function changeLink() {
         alert('called changeLink');
         ...
     }
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012461
yep, not firing
0
 
LVL 1

Author Comment

by:Shawn
ID: 35012489
:-D that did it. Found the first body and inserted it. works perfectly now.

thank you!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35012493
Great!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

800 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