473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

leave button disabled if textbox has a whitespace

hal
I have a web page using javascript to enable/disabled an image button
and switch its image when values are entered into a couple of
textboxes. I have all that working fine, but my code considers a
space a value. Anyone have any idea how to keep my button disabled if
spaces are entered into the textboxes? Below is my code:

<script type="text/javascript">

function SetImage()
{
var
txtAnswer1=document.getElementById("txtAnswer1").v alue;
var
txtAnswer2=document.getElementById("txtAnswer2").v alue;

if (txtAnswer1.length 0 && txtAnswer2.length 0)
{
var y=document.getElementById("btnSubmit");
y.src = "../Images/submit_active.gif";

window.document.getElementById("btnSubmit").disabl ed = false;
}

if (txtAnswer1.length == 0 || txtAnswer2.length == 0)
{
var y=document.getElementById("btnSubmit");
y.src = "../Images/submit_inactive.gif";

window.document.getElementById("btnSubmit").disabl ed = true;
}
}

</script>

<asp:TextBox ID="txtAnswer1" runat="server" MaxLength="255"
onKeyUp="SetImage()"></asp:TextBox>
<asp:TextBox ID="txtAnswer2" runat="server" MaxLength="255"
onKeyUp="SetImage()"></asp:TextBox>

Thanks
Jun 27 '08 #1
1 1351
On May 21, 1:40*am, hal <hled...@gmail.comwrote:
I have a web page using javascript to enable/disabled an image button
and switch its image when values are entered into a couple of
textboxes. *I have all that working fine, but my code considers a
space a value. *Anyone have any idea how to keep my button disabled if
spaces are entered into the textboxes? *Below is my code:

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

* * * * function SetImage()
* * * * * {
* * * * * * var
txtAnswer1=document.getElementById("txtAnswer1").v alue;
* * * * * * var
txtAnswer2=document.getElementById("txtAnswer2").v alue;

* * * * * * if (txtAnswer1.length 0 && txtAnswer2.length 0)
* * * * * * * * * * {
* * * * * * * * * * * * var y=document.getElementById("btnSubmit");
* * * * * * * * * * * * y.src = "../Images/submit_active.gif";

window.document.getElementById("btnSubmit").disabl ed = false;
* * * * * * * * * * }

* * * * * * if (txtAnswer1.length == 0 || txtAnswer2.length == 0)
* * * * * * * * * * {
* * * * * * * * * * * * var y=document.getElementById("btnSubmit");
* * * * * * * * * * * * y.src = "../Images/submit_inactive.gif";

window.document.getElementById("btnSubmit").disabl ed = true;
* * * * * * * * * * }
* * * * * }

* * </script>

<asp:TextBox ID="txtAnswer1" runat="server" MaxLength="255"
onKeyUp="SetImage()"></asp:TextBox>
<asp:TextBox ID="txtAnswer2" runat="server" MaxLength="255"
onKeyUp="SetImage()"></asp:TextBox>

Thanks
var txtAnswer1=document.getElementById("txtAnswer1").v alue;
var txtAnswer2=document.getElementById("txtAnswer2").v alue;

txtAnswer1 = txtAnswer1.replace(/^\s*|\s*$/g,"");
txtAnswer2 = txtAnswer2.replace(/^\s*|\s*$/g,"");

if (txtAnswer1.length 0 && txtAnswer2.length 0)
..........
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Galahad | last post by:
Here's the question: I have a form w/ TextBox controls and a Search Button control. Once the user clicks the Search Button, they get a Modal dialog w/ a datagrid that contains their search...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
6
by: M O J O | last post by:
Hi, I have a webform with a textbox and a button. When the textbox is empty (=""), I want the button to be disabled. When the user enters text in the textbox, the button must be enabled. Is...
2
by: AussieRules | last post by:
Hi, I have a form with many textbox on it. Behind this(so to speak), is a class, and each time the user changes the value of the text box I want to update the relevant property of the class. ...
3
by: Tom | last post by:
I have a VB .NET application that has a text box with the following code to handle the leave event. Private Sub txtIDiscountRate_TextChanged(ByVal sender As System.Object, ByVal e As...
0
by: campwes | last post by:
I am trying to simulate multiple web pages by putting the content within panel controls, and then changing the visibility as needed: panel1.Visible = False panel2.Visible = True In panel1,...
2
by: teddy.am | last post by:
Guys, I have a set of 6 radio buttons, infront of each one there's a textbox .... i need all textboxes disabled .... once one of the radio buttons is selected, the texbox infront of it will be...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
5
by: andersond | last post by:
I need to enable or disable a submit button based on the value of a data field stored in a database. I have found working examples of how to enable or disable based on a checkbox; but, I need it to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.