/    Sign up×
Community /Pin to ProfileBookmark

NoScript Validation

Hi,

Can anyone help me with a simple JavaScript where if the clients JavaScript is disabled, then the submit button will be grayed out?

Thanks.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@xelawhoDec 21.2011 — you're looking for a javascript that will work if the client's javascript is disabled?

I think you have to work it the other way - start the button off as disabled, then use javascript to enable it:

[CODE]
<body>
<input type="submit" id="sub" disabled="true">
<script>
document.getElementById("sub").disabled=false;
</script>
</body>
[/CODE]
Copy linkTweet thisAlerts:
@llckllauthorDec 21.2011 — Duh good point.
Copy linkTweet thisAlerts:
@xelawhoDec 21.2011 — but possible - see my edited post above ?
Copy linkTweet thisAlerts:
@rtretheweyDec 21.2011 — I believe this should do what you want:

<i>
</i>&lt;script type="text/javascript"&gt;
document.write('&lt;input type="submit" value="Submit"&gt;');
&lt;/script&gt;
&lt;noscript&gt;
&lt;input type="submit" value="Submit" disabled="true"&gt;
&lt;/noscript&gt;


Just insert it where you want your Submit button to appear.
Copy linkTweet thisAlerts:
@JunkMaleDec 22.2011 — Why? What is the porpose of forcing someone in to Javascript?

Have you considered the vast majority of internet users access from a PDA, Mobile phone or other portable device and that these browsers have limited or no javascript support?

My mobile phone for example understands javascript but it can not handle some things like pop ups, they simply do not exist.

If you insist on using javascript, then using something like...
[CODE]function firemeupbaby(){
document.getElementById("theButton").disabled = false;
}[/CODE]


[code=html]<body onload="firemeupbaby()">
<input name="theButton" id="theButton" type="button" value="Click Me">
[/code]


When the page loads, if JS is enabled, the disabled button will enable so it can be clicked otherwise if will remain greyed out.
Copy linkTweet thisAlerts:
@xelawhoDec 22.2011 — When the page loads, if JS is enabled, the disabled button will enable so it can be clicked otherwise if will remain greyed out.[/QUOTE]

no... because the button has to start off as disabled. Apart from that, it's hard to see how your code differs in any real way from what I posted in #2 ?
Copy linkTweet thisAlerts:
@JunkMaleDec 23.2011 — SO, I missed off the disabled, that part should have been easily worked out.

[code=html]<body onload="firemeupbaby()">
<input name="theButton" id="theButton" type="button" value="Click Me" disabled>[/code]


Happier?
Copy linkTweet thisAlerts:
@xelawhoDec 23.2011 — verging on the ecstatic ?
Copy linkTweet thisAlerts:
@JunkMaleDec 23.2011 — Wonderful... ?
Copy linkTweet thisAlerts:
@KorDec 23.2011 — 
Have you considered the vast majority of internet users access from a PDA, Mobile phone or other portable device and that these browsers have limited or no javascript support?[/QUOTE]

eeer, what? If a portable device has a browser, that browser does run the vast majority of the javascript methods. There are some exceptions, bugs, etc, but they are few and not so important. And, no, the vast majority of internet users still access the web from a workstation (PC, MAC) or a notebook. That means under a Windows or an Apple Operating System. So far.

But, yes, you are right about accessibility. Whenever is possible, the developer should try to make his site accessible to everyone, with or without javascript.
Copy linkTweet thisAlerts:
@JunkMaleDec 23.2011 — Point I am making is that mobile phones that are smart, like mine which will run javascript and java but the browser can not handle things like popups.

It does help to understand why the button has to be disabled in the first place, why javascript needs to be relied upon. A programmer should always be looking at some level of redundancy back up plans if the primary method fails and it should be a graceful degrade and not one of the many kicking and screaming ones that *itch about you should turn things on... My philosophy in these situations is simple, If it aint on buddy, you moaning about it aint gonna make owt difference. Then 'X' click. Bye!
Copy linkTweet thisAlerts:
@KorDec 23.2011 — Yes, JunkMale, I have already said that you are right regarding the general philosophy of creating HTML/JavaScript codes as accessible as possible.

Regarding pop-ups, that's not a big loss. For instance on all my browsers I have installed add-ons in order to block the pop-ups. Pop-ups are hated by everyone, thus this technique is now considered deprecated and irritating.
×

Success!

Help @llckll spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...