• 0

[javescript] hidden submit button


Question

how do i make the submit button disabled till a key code is entered

<script>
if ( window.addEventListener ) { 
 var state = 0, hake = [38,38,40,40]; 
 window.addEventListener("keydown", function(e) { 
	if ( e.keyCode == hake[state] ) state++; 
	else state = 0; 
	if ( state == 10 ) 
	///BUTTON///<input type="submit" value="Submit">
	}, true); 
}
</script>

Link to comment
https://www.neowin.net/forum/topic/890050-javescript-hidden-submit-button/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

How about this...

<script>
if ( window.addEventListener ) { 
 var state = 0, hake = [38,38,40,40]; 
 window.addEventListener("keydown", function(e) { 
	    if ( e.keyCode == hake[state] )
                state++; 
	    else
                state = 0;

            //Disable or enable the button based on the state
	    document.getElementById("buttonIDHere").disabled = (state != 10 )
	}, true); 
}
</script>

You'll need to give your button a unique ID to do this so that your javascript can find the correct button. So for your button, you'll need the following syntax...

<input id="buttonIDHere" type="submit" value="Submit" disabled="disabled" />

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.