Skip to main content
Gene_Godsey
Inspiring
May 19, 2011
Question

onChange method

  • May 19, 2011
  • 2 replies
  • 966 views

I know this is a JavaScript issue but I will go ahead and ask this anyway.

I need a javascript function that will allow my textbox to enable the submit button in the form when the textbox becomes populated with text.

Thanks in Advance.....

This topic has been closed for replies.

2 replies

Inspiring
May 31, 2011

Dan,

I do not know whether you have an aswer yet but if your intention is

to stop a form from submitting when the text box is blank you may create a function that

ensures that the field is not blank, and have the function called on submit.

<script type="text/javascript" language="javascript">

function ensureNotBlank (){

if (document.formname.fieldname.value == ""){
  alert('Please enter a whaterver');
  return false;

}

}

</script>

On your submit button:

<input type submit" value="Send data" onClick="return ensureNotBlank()">

If the textbox is blank you have the alert and the form is not submitted. If it is populated the form submits.

Allan

Gene_Godsey
Inspiring
May 31, 2011

This is a possible solution but what I was really looking for was to keep the submit button disabled until the textbox was populated with content.

Inspiring
May 19, 2011

Your google search string is "javascript show hide"

Gene_Godsey
Inspiring
May 24, 2011

That is one idea BUT.............

I need to have a method that the trigger an event via a textbox insertion/callback that will enable the submit button w/o having to use the onKeyUp method. The actual text field is hidden and the field needs to enable the disabled submit button.

I.E.:

-------------------------------------------

<script language="javascript" type="text/javascript">
function SetButtonStatus(sender, target) {
    if ( sender.value.length >= 1 )
    document.getElementById(target).disabled = false;
     else
    document.getElementById(target).disabled = true;
}
<script>

<asp:TextBox ID="txtText" runat="server" onkeyup="SetButtonStatus(this, 'btnButton')">asp:TextBox>
<asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" />

-------------------------------------------

Sorry it's in Dot.Net but you get the idea.

Inspiring
May 24, 2011

You want to use the value of a hidden field to enable/disable the submit button?  Is there user input involved anywhere?