Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:03:16+00:00 2026-06-14T09:03:16+00:00

Hey so I have two text boxes and a button. I only wanted the

  • 0

Hey so I have two text boxes and a button. I only wanted the button enabled when the “playerName” textbox contains something and the “upperLimit” textbox contains a integer > 0.
I want the button to start disabled then dynamically change as the user is typing in the textbox, constantly checking whats in the textboxes to see if the button should be activated. Heres what I’ve tried:

JavaScript:

var playerNameValid = false;
var upperLimitValid = false;


function validatePlayerName()
{
    if (document.getElementById("initialPlayerNameChoice").Value == "")
    {
        playerNameValid = false;
        document.getElementById("startGameButton").disabled = true;
    }
    else
    {
        playerNameValid = true;

        if (upperLimitValid == true)
        {
            document.getElementById("startGameButton").disabled = false;
        }
    }
}


function validateUpperLimit()
{
    if (isNaN(document.getElementById("initialUpperLimitChoice").valuetextContent))
    {
        upperLimitValid = false;
        document.getElementById("startGameButton").disabled = true;
    }
    else
    {
        upperLimitValid = true;

        if (playerNameValid == true)
        {
            document.getElementById("startGameButton").disabled = false;
        }
    }
}

Markup:

<asp:Label ID="enterNameLabel" runat="server" Text="Enter your name: "></asp:Label>
<asp:TextBox ID="initialPlayerNameChoice" runat="server"></asp:TextBox>
<br /><br/>
<asp:Label ID="enterUpperLimitLabel" runat="server" Text="Enter upper limit: "></asp:Label>
<asp:TextBox ID="initialUpperLimitChoice" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="startGameButton" enabled="false" runat="server" Text="Start Game" />

Code Behind:

    initialPlayerNameChoice.Attributes.Add("onkeyup", "javascript:validatePlayerName()");
    initialUpperLimitChoice.Attributes.Add("onkeyup", "javascript:validateUpperLimit()");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:03:17+00:00Added an answer on June 14, 2026 at 9:03 am

    You’ve almost got it. There are just a few lines you need to fix in your code:

    if (document.getElementById("initialPlayerNameChoice").Value == "")
    //In JavaScript there is no property called 'Value' -----^  use 'value' instead:
    if (document.getElementById("initialPlayerNameChoice").value == "")
    
    
    if (isNaN(document.getElementById("initialUpperLimitChoice").valuetextContent))
    //Again, in JavaScript there is no property called 'valuetextContent' ---^
    //Furthermore, 0 is a number, so if you kept this, the button would enable on 0
    //You can use a regular expression to make sure it is a number > 0, and
    //re-arranging your function eliminates re-checking of logic:
    function validateUpperLimit()
    {
      var num = document.getElementById("initialUpperLimitChoice").value.match(/^\d+$/);
      if(num && num[0] > 0)
      {
        upperLimitValid = true;
    
        if (playerNameValid == true)
        {
          document.getElementById("startGameButton").disabled = false;
        }
      }
      else
      {
        upperLimitValid = false;
        document.getElementById("startGameButton").disabled = true;
      }
    }
    

    Another solution that you could implement is having just a validate() function, and having both fields call that onkeyup. If you changed your validation functions to return true or false, then you could eliminate the use of global variables and the logic makes more sense.

    function validate(){
      if(validatePlayerName() && validateUpperLimit())
        document.getElementById('startGameButton').disabled = false;
      else
        document.getElementById('startGameButton').disabled = true;
    }
    
    function validatePlayerName(){
      if(document.getElementById('initialPlayerNameChoice').value != '')
        return true;
      else
        return false;
    }
    
    function validateUpperLimit(){
      var num = document.getElementById('initialUpperLimitChoice').value.match(/^\d+$/);
      if(num && num[0] > 0)
        return true;
      else
        return false;
    }
    

    And then instead for your onkeyup code (I don’t think you need the javascript: part but I’m not completely sure so if it barks at you, just throw it back in):

    initialPlayerNameChoice.Attributes.Add("onkeyup", "validate()");
    initialUpperLimitChoice.Attributes.Add("onkeyup", "validate()");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everybody, this is what I have going on. I have two text files.
hey guys what I am trying to do is have two edit boxes for
So I have two files, one that contains my text, and another which I
Hey everyone, I want to start using Scheme and I have two questions. First,
Hey I have a problem comparing the value of a CGPoint (struct with two
Hey, need a little help here. I have two models: class User < ActiveRecord::Base
Hey all i have two JFrames one is my main login frame, user enters
Hey guys, so I have two models in my project, grinders, and votes. So
Hey guys. I have a question. I have two different arrays with different structure
Hey everyone! I am having trouble with understanding modules -- I have two files,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.