• 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.
  • Posts

    • Lets just hope they don't jump to an American corporation like RedHat.
    • Does today Linux still ask you to compile something for something to work? if Yes, lets wait for another 10 years.
    • No point really. I rarely get any responses to it. Btw, Bing is also an embarrassment for MS for the same reasons. The MS fans around here never engage as they have have no defence to it.
    • "Microsoft Trump" suite maybe something Trump regime will make it happen by blackmailing them.
    • MusicPod 2.13.0 by Razvan Serea MusicPod is a super simple app that lets you play your music, listen to podcasts, and stream internet radio—all in one place. Just open it, add your music files, or search for something cool to listen to. No complicated menus, no confusing settings—just play, pause, skip, and enjoy. It supports all the usual music formats like MP3, FLAC, and M4A, and it even remembers your favorite stuff. You can also find and follow podcasts, download episodes to listen offline, and browse radio stations by name, tag, or country. It looks clean, runs fast, and is totally free. MusicPod does the job without getting in your way. MusicPod key features: Supports major audio formats like MP3, FLAC, M4A, and MP4 Organizes your local music library by title, album, or artist Built-in podcast search, subscriptions, and offline downloads Stream internet radio by name, tag, or country Pin your favorite albums, podcasts, and stations Create and manage custom playlists Smart, minimalist interface that's easy to use Stream or download media Notifications for new podcast episodes Built with Flutter for smooth, cross-platform performance MusicPod 2.13.0 changelog: bring back blur as an option, add generated l10n, fix connectivity handler (#1324) (d04834d) Translated using Weblate (Chinese (Simplified Han script)) (#1310) (20003ff) Translated using Weblate (Swedish) (#1327) (5247d62) Translations update from Hosted Weblate (#1320) (84b5c00) Translations update from Hosted Weblate (#1322) (8e1a881) Translations update from Hosted Weblate (#1325) (8027f61) Translations update from Hosted Weblate (#1328) (358ff0f) Bug Fixes missing system color icon (#1333) (7346176), closes #1302 unify ways of presenting chips in the app (#1330) (da2a8f6) Download: MusicPod 2.13.0 | 28.6 MB (Open Source) Links: MusicPod Website | MacOs | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • First Post
      LsDmT earned a badge
      First Post
    • One Month Later
      evershinefacilityservice earned a badge
      One Month Later
    • Week One Done
      evershinefacilityservice earned a badge
      Week One Done
    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • Week One Done
      Orpheus13 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      569
    2. 2
      ATLien_0
      256
    3. 3
      +Edouard
      163
    4. 4
      +FloatingFatMan
      157
    5. 5
      Michael Scrip
      110
  • Tell a friend

    Love Neowin? Tell a friend!