473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Detecting if JavaScript is enabled

Hi,

This is certainly a simple question, but I'm a newbie in JavaScript.

Is there a way to know if JavaScript is enabled?

My php script uses JavasSript to do something. If JavaScript is not
enabled, I can put a "submit" push button. But I don't want both (the
"submit" push button with the automatic action), so I want to know on
the fly which one I must use (whether JavaScript is enabled).
Aug 20 '08 #1
12 2768
Anic297 wrote on 20 aug 2008 in comp.lang.javascript:
Hi,

This is certainly a simple question, but I'm a newbie in JavaScript.

Is there a way to know if JavaScript is enabled?
<script type='text/javascript'>
document.write('Javascript is enabled');
</script>
My php script uses JavasSript to do something.
Impossible, as PHP only runs serverside, and Javascript runs clientside.

[Well it can run serverside on ASP, but not on PHP]
If JavaScript is not
enabled, I can put a "submit" push button. But I don't want both (the
"submit" push button with the automatic action),

<input type='submit' id='myButton'>
<script type='text/javascript'>
document.getelementById('myButton').style.display = 'none';
</script>
so I want to know on
the fly which one I must use (whether JavaScript is enabled).
That is not about you knowing, but about programming for it.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 20 '08 #2
Anic297 wrote:
Is there a way to know if JavaScript is enabled?
I can write you a script if you can write me a program that detects if the
computer is running that the program is running on.
My php script uses JavasSript to do something.
That's unlikely.
If JavaScript is not enabled, I can put a "submit" push button. But I
don't want both (the "submit" push button with the automatic action), so
I want to know on the fly which one I must use (whether JavaScript is
enabled).
<form action="foo.php" onsubmit="...; return false">
...
<input type="submit" ...>
...
</form>

This was a FAQ, please search the archives before you post.
<http://jibbering.com/faq/>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 20 '08 #3
Evertjan. a écrit:
>My php script uses JavasSript to do something.

Impossible, as PHP only runs serverside, and Javascript runs clientside.
Yes... I have to learn that...
>If JavaScript is not
enabled, I can put a "submit" push button. But I don't want both (the
"submit" push button with the automatic action),

<input type='submit' id='myButton'>
<script type='text/javascript'>
document.getelementById('myButton').style.display = 'none';
</script>
Oh, yes, hiding the button from JavaScript only if it's enabled!
>so I want to know on
the fly which one I must use (whether JavaScript is enabled).

That is not about you knowing, but about programming for it.
Well, I do desktop programming, but web programming is not the same thing!

Thank you!
Aug 20 '08 #4
Thomas 'PointedEars' Lahn a écrit:
>Is there a way to know if JavaScript is enabled?

I can write you a script if you can write me a program that detects if the
computer is running that the program is running on.
Well... perhaps not a JavaScript script...
(but I have had my answer)
>My php script uses JavasSript to do something.

That's unlikely.
Well, I don't use correct terms (I'm new in web programming). I just
expected readers to understand my phrases.
This was a FAQ, please search the archives before you post.
<http://jibbering.com/faq/>
Thanks
Aug 20 '08 #5
Anic297 wrote:
Hi,

This is certainly a simple question, but I'm a newbie in JavaScript.

Is there a way to know if JavaScript is enabled?
Ignoring the details of what you'd do on the server side with this
knowledge, and even whether knowing this is generally useful, and your
application can work with an initial form that doesn't need to
specifically know whether JavaScript is available or not, you could
then have a script that runs on the page that uses the DOM api to add
a hidden input element to the form, where the hidden value indicates
that JavaScript is present. When the form is submitted, either by the
user or by JavaScript, the server-side code would then be informed
whether the browser had JavaScript enabled.
Aug 20 '08 #6
Anic297 wrote:
Evertjan. a écrit:
>>My php script uses JavasSript to do something.
Impossible, as PHP only runs serverside, and Javascript runs clientside.

Yes... I have to learn that...
And to unlearn it afterwards. Neither language is restricted to client-side
oder server-side use. It is only that PHP is more often used server-side,
while ECMAScript implementations are probably more often used client-side.
>>If JavaScript is not
enabled, I can put a "submit" push button. But I don't want both (the
"submit" push button with the automatic action),
<input type='submit' id='myButton'>
<script type='text/javascript'>
document.getelementById('myButton').style.display = 'none';
document.getElementById(...)...

But document.forms[...].elements["myButton"] is more compatible.
></script>

Oh, yes, hiding the button from JavaScript only if it's enabled!
This solution can be recommended against as it introduces a dependency on
the CSS DOM needlessly.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Aug 20 '08 #7
Evertjan. a écrit:
<input type='submit' id='myButton'>
<script type='text/javascript'>
document.getelementById('myButton').style.display = 'none';
</script>
Hi,
Despite the fact that the code is simple, I can't get it to work.
Here's the source code from my browser:
Select a QuickTime Movie:
<FORM ACTION="./moviesindex.php?movieskind=qt" METHOD="post" NAME="nav2">
<SELECT NAME="url"
onChange="document.location.href=document.nav2.url .options[document.nav2.url.selectedIndex].value">
<OPTION VALUE=./moviesindex.php?movieskind=qt&moviename=mov1>Mouth
<OPTION VALUE=./moviesindex.php?movieskind=qt&moviename=mov2>Eyes
.... (other options)
</SELECT>

<INPUT TYPE="SUBMIT" id="MovieButton" VALUE="Clic here if the page does
not update">

<script type='text/javascript'>
document.getelementById("MovieButton").style.displ ay = "none";
</script>
</FORM>

I think it should not make any difference (since the code above is the
result), but all is done in php (I send all using the "echo" command).

I also tried using "<script language='Javascript'>".

It's hard when you know programming but not web programming: you know
logical ways of doing things, but the syntax and principles are totally
differents (I start from scratch)!

What do you suggest?
Aug 20 '08 #8
Thomas 'PointedEars' Lahn a écrit:
And to unlearn it afterwards. Neither language is restricted to client-side
oder server-side use. It is only that PHP is more often used server-side,
while ECMAScript implementations are probably more often used client-side.
Ok...
>> document.getelementById('myButton').style.display = 'none';

document.getElementById(...)...
You know, I had replied to "Evertjan."'s post because it didn't worked
(even with differences). Now, I have removed my unnecessary post ;-)
But document.forms[...].elements["myButton"] is more compatible.
Ok...
>Oh, yes, hiding the button from JavaScript only if it's enabled!

This solution can be recommended against as it introduces a dependency on
the CSS DOM needlessly.
I think it's an interessant approach, anyway.

Thank you for all this!
Aug 20 '08 #9
If JS is NOT enabled there is nothing you can do in the client side so you
must write your code assuming it is off.

Have this <body onload='js_exist_code' Then if JS is active (on) the
function 'js_exist_code' runs and changes stuff to the JS version. A lot
can be done by just using style stuff and changing className of some
elements.

This fails if the user turn JS after loading. <g>

HTH

Aug 20 '08 #10
david.karr a écrit:
You could then have a script that runs on the page that uses the DOM api
to add a hidden input element to the form, where the hidden value
indicates that JavaScript is present. When the form is submitted,
either by the
user or by JavaScript, the server-side code would then be informed
whether the browser had JavaScript enabled.
Yes, that would work if I want to know the enabled state of JavaScript
when data are submitted. In my case, I want to know that when the page
is being written.

Thanks, it will be good to know for the future.
Aug 20 '08 #11
Dr***********@nyc.rr.com a écrit:
If JS is NOT enabled there is nothing you can do in the client side so you
must write your code assuming it is off.
Well, I have an alternative (either it's called by an event in
JavaScript or a push button appears). In this case, I think it's good to
know.
Have this <body onload='js_exist_code' Then if JS is active (on) the
function 'js_exist_code' runs and changes stuff to the JS version. A lot
can be done by just using style stuff and changing className of some
elements.
Hmmm... I'm not yet at this degree of knowledge ;-)
This fails if the user turn JS after loading. <g>
Good point, indeed.
(in my actual case, it's worse if the user turns JS on, not off, after
loading.
Thank you.
Aug 20 '08 #12
Evertjan. a écrit:
<input type='submit' id='myButton'>
<script type='text/javascript'>
document.getelementById('myButton').style.display = 'none';
</script>
Yes, it works (as expected)! Thank you very much!
Aug 20 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: dave yan | last post by:
hi, i have some forms which use javascript for data validation, e.g., checking to make sure all required fields are completed, checking that data falls within valid ranges for certain fields,...
20
by: Mandy Memphis | last post by:
If I perform a mousedown within a document, move the mouse outside the browser window, and then release the mouse button, the document.onmouseup event does not fire. Is there any way to detect a...
7
by: Michael Crute | last post by:
I did a search and basically came up with nothing for this question, but if I missed the answer, I apologize in advance, please just point me in the right direction. OK, I am using a JavaScript...
25
by: Ryan Stewart | last post by:
I'm working on a project to collect web application usage statistics. What are the recommended ways of detecting whether a browser is JavaScript enabled and/or capable? Obviously I can write a...
11
by: Dag Sunde | last post by:
We have this web-app that requires Javascript to be enabled in the UA (this is okay'ed by our customer). Now I want to make a "pre" page before the login screen, informing the user that he/she...
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
4
by: Samba | last post by:
Hi, I'm having a very genuine problem: I'm developing an ASP.NET web application. Since I'm using a lot of Javascripts in my pages, I want to ensure that my clients do not disable Script in...
2
by: Barry | last post by:
Hi How do i detect if the browser has javascript enabled. Note: i am not refereing to Request.Browser.javascript Barry
2
by: ron | last post by:
Hi, I working on a .net web project which need to check javascript disabled or enabled. I use the code below: If Request.Browser.JavaScript = True Then .... end if The problem is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.