Disable Submit until 3 characters are entered

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Disable Submit until 3 characters are entered

Post by simonmlewis »

Hello. I don't know anything about writing Javascript, and cannot find anything online that does this.

I want to disable the 'submit' button until at least 3 characters have been entered into the form.

I suspect it must do this via a hidden count, but no idea how to do this. Can anyone please help?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Sofw_Arch_Dev
Forum Commoner
Posts: 60
Joined: Tue Mar 16, 2010 4:06 pm
Location: San Francisco, California, US

Re: Disable Submit until 3 characters are entered

Post by Sofw_Arch_Dev »

Simonmlewis,

unfortunately you're probably going to have to learn some Javascript and CSS. You want to leverage the onkeydown event on the input element in question.

Code: Select all

 
<input  ... onkeydown="myCharCounter();" .../>
 
That function is going to set the css display property of the aforementioned submit button. You'll use things like

Code: Select all

 
var obj= document.getElementById( 'mySubmitButtonId');
 
and then set the display css property accordingly. There are more advanced ways of doing this, but they require a basic understanding of JavaScript fundamentals which you should acquire first.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Disable Submit until 3 characters are entered

Post by simonmlewis »

Thanks. I have absolutely not a clue with javascript, so I am not really any further.

What would be useful is if i was shown how to do something, and explain what it is that is being shown.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply