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 / December 2007

Tip: Looking for answers? Try searching our database.

Javascript undefined in aspx page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C - 04 Dec 2007 14:38 GMT
I have an aspx page with Javascript inside a script block at the end of my
aspx page. I am trying to show or hide 2 tables inside a FormView but I keep
getting the value in Javascript as "undefined" and I cannot understand why.
It occurs when I try to set the value of a variable to one I set at the top
of the page.  I have also tried it with getElementById (commented out) and
it gives me the same thing.  The variable ssaleleasecode is getting the
undefined message. Can anyone spot the problem?  Thanks.  Below is the
Javascript code:
David

   if ((document.getElementById('fvPropertyClosings_SaleTable') != null) ||
(document.getElementById('fvPropertyClosings_LeaseTable') != null))
       var ssaleleasecode = '<%=strLeaseSaleCode %>';
       //var obj = document.getElementById('txtSaleOrLease');
       //var ssaleleasecode = obj.value;
       alert('strLeaseSaleCode=' + ssaleleasecode);
       if (ssaleleasecode == 'S')
       {
           var otbl =
document.getElementById('fvPropertyClosings_SaleTable');
           otbl.className = 'Show';
           otbl = document.getElementById('fvPropertyClosings_LeaseTable');
           otbl.className = 'Hide';
           calcpriceper();

       }else{
           if (ssaleleasecode == 'L')
           {
           var otbl =
document.getElementById('fvPropertyClosings_LeaseTable');
           otbl.className = 'Show';
           otbl = document.getElementById('fvPropertyClosings_SalesTable');
           otbl.className = 'Hide';
           }
       }
Mark Rae [MVP] - 04 Dec 2007 15:21 GMT
> Can anyone spot the problem?

If you do a View Source, can you find the object called
fvPropertyClosings_SaleTable? If so, is that only part of the object's
name...?

If so, change your code to e.g.

if ((document.getElementById('<%=fvPropertyClosings_SaleTable.ClientID%>')
!= null) ||

etc

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

David C - 04 Dec 2007 16:23 GMT
Yes, it was an object name problem.  Thanks.

David

>> Can anyone spot the problem?
>
[quoted text clipped - 8 lines]
>
> etc

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.