Hello. i was wondering if this can be done,personally my knowledge of Java / ajax is bad..

How can i make the submit button unable to be clicked if there is no data in the input (usermsg)?

<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="100" />
<input name="submitmsg" type="submit"  id="submitmsg" value="Send" />
</form>

If you have any idea, please help me.
Cheers,
Sorcher

hi,
Please try this code.

<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="100" onkeyup="EnableButton();"/>
<input name="submitmsg" type="submit"  id="submitmsg" value="Send" disabled="true"/>
</form>

<script>
function EnableButton(){
	var submitObj = document.getElementById('submitmsg');
	submitObj.disabled = false;
	if(document.getElementById('usermsg').value=="")	{
		submitObj.disabled = true; }
}
</script>

If you want to want the button to remain disabled if you enter a space (or 2), add .replace(/^\s+|\s+$/g,'') after .value .

The options didnt work :/

<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="100" onkeyup="EnableButton();"/>
<input name="submitmsg" type="submit"  id="submitmsg" value="Send" disabled="true"/>
</form>
 
<script>
function EnableButton(){
	var submitObj = document.getElementById('submitmsg');
	submitObj.disabled = false;
	if(document.getElementById('usermsg').value=="")	{
		submitObj.disabled = true; }
}
</script>

Works one time,but after the user has used it once,the code is not enabled anymore

It works fine for me, what browser doesn't it work for?

By the way, you can somewhat simplify the script to just:

<form name="message" action="">
	<input name="usermsg" type="text" id="usermsg" size="100" />
	<input name="submitmsg" type="submit"  id="submitmsg" value="Send" disabled="true" />
</form>
 
<script>
var submit = document.getElementById('submitmsg');
document.getElementById('usermsg').onkeyup = function() {
	submit.disabled = this.value == '';
};
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.