0

I have a website that allows users to create new content and I use javascript as a way to check for spam. If user has javascript turned off how can I hide or disable the post search button

<input type="submit" name="submitmee" id="creatingpost" value="Post" />

Is there a combination of if statements or noscripts that I can use. I have seen some examples online but they all redirect user, im trying to do something like

if(javascript== off)
{
    /* please turn on javascript */
}
else
{
    /* show button */
}
1

2 Answers 2

3

You could just use a noscript tag, in your head that is only loaded when javascript is disabled.

HTML

<noscript>
    <style type="text/css">
         #creatingpost {
           display: none; 
         }

         #noJsBanner
         {
            display: block;
         }
    </style>
</noscript>

Check this demo with JavaScript disabled.

Sign up to request clarification or add additional context in comments.

Comments

1

Why not show the "no JS" version by default and toggle it with JavaScript (that will obviously only run if JS is enabled)?

HTML:

<div class="js-show">
    <input type="Submit" value="Go!" />
</div>
<div class="js-hide">
    <p>Please switch JavaScript on.</p>
</div>

CSS:

.js-show
{
    display: "none";
}

JavaScript (jQuery):

$(function() {
    $('.js-hide').hide();
    $('.js-show').show();
});

Fiddle.

Alternatively, you could place a "no-js" class on the html element and swap it for "js" on document.ready, then style things with these classes accordingly.

Either of these approaches gives you a flexible way of creating JS-free alternatives for features across your entire site with only a couple of lines of code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.