Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

leave button disabled if textbox has a whitespace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hal - 21 May 2008 00:40 GMT
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").value;
           var
txtAnswer2=document.getElementById("txtAnswer2").value;

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

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

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

window.document.getElementById("btnSubmit").disabled = 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
Alexey Smirnov - 21 May 2008 08:23 GMT
> 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
[quoted text clipped - 36 lines]
>
> Thanks

var txtAnswer1=document.getElementById("txtAnswer1").value;
var txtAnswer2=document.getElementById("txtAnswer2").value;

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

if (txtAnswer1.length > 0 && txtAnswer2.length > 0)
..........

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.