Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2005, 10:40 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking to see if a label's text is empty

Hi,

I've been getting errors saying "Object required" when I try to check the contents of a label's text. I'm trying to have the function execute only if the label's text is blank. The following is my code:

    <script>
  function NewWindow()
  {
    if (document.getElementById("txtpostdte").value != "")
    {
        var rptdate=document.getElementById("txtpostdte").valu e;
        var err=document.getElementById("lblerror").innerHTML;
        if (err = "")
        {
        window.open("TyDly.aspx?postdte=" + rptdate);
        }
    }
  }
        </script>

The error is pointing to where I set the variable 'err' equal to the lblerror's text. Is there something I'm doing wrong? I tried .innertext, .text, .value and still nothing works. In addition, is there any chance that I can combine both the txtpostdte and lblerror's conditions together? When I try to do it, I get an error. Any help is greatly appreciated. Thanks.

And, I'm not sure if this is the forum to post this in. If not, can someone please point me in the right direction? Thanks again.


 
Old October 26th, 2005, 10:45 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have edited my code to the following:

<script>
  function NewWindow()
  {
    if (document.getElementById("txtpostdte").value != "")
    {
        var rptdate=document.getElementById("txtpostdte").valu e;
        var err=document.getElementById("lblerror").innerHTML;
        if (err == "")
        {
        window.open("TyDly.aspx?postdte=" + rptdate);
        }
    }
  }
        </script>

However, I'm still getting the same error.

 
Old October 26th, 2005, 11:05 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've noticed something really weird about this program. Sometimes it works and sometimes it doesn't. Whenever the label contains something, it's fine. But, when it's blank, it only works once and then gives me the "Object required" error. Does it not like it when it's blank? Is there something I can do differently? Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking to see if a label's text is empty mh ASP.NET 2.0 Basics 2 October 26th, 2005 10:38 AM
Help checking for empty dataset Payback ASP.NET 1.0 and 1.1 Basics 5 March 28th, 2005 05:00 AM
Checking for empty string richw32001 General .NET 1 August 8th, 2004 01:37 PM
checking for empty recordsets ! spraveens Classic ASP Databases 0 September 9th, 2003 10:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.