2

So I have this:

<form action="results.html" class="pure-form" accept-charset="unicode">
<input type="hidden" name="cx" value="017807894282691686756:y12pdghija8"/>
<input type="hidden" name="ie" value="utf-8" />
<input type="text" name="q" placeholder="" size="50"/>
  <input type="submit" class="pure-button" src="" value="Search"/>
</form>

It works just fine, but is there a way to make the button not clickable if there is nothing in the text box? Or just making the button do some other action if you don't write anything in the text box? Basically just how google has it, if you don't have anything in the box it doesn't do anything.

1
  • 1
    You can use JavaScript to detect whether there is anything typed, and grey-out/hide the submit button if there isn't.
    – TylerH
    Jun 2, 2014 at 19:45

2 Answers 2

0

You could do this with JavaScript and the setInterval function. It'll look something like this:

<script>
 window.setInterval(function() {
  var length = document.getElementsByName('q')[0].value.length;
  document.getElementsByClassName('pure-button')[0].disabled = !length;
 }, 100);
</script>

It would be easier if you used ids.

1
  • Thank you, that was perfectly what I wanted. I tried the other ones as well, but they didn't work as fine as your does. People like you are the stars of the community :)
    – TwiXSK
    Jun 2, 2014 at 19:58
0

You can do it easly with javascript (jQuery).

Check this answer: disable submit button if inputs are empty with jQuery

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.