473,395 Members | 1,969 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,395 software developers and data experts.

Every ID is undefined

1,271 Expert 1GB
Question from a javascript newbie ...
I'm having trouble getting this simple thing to work
Expand|Select|Wrap|Line Numbers
  1. ClickNumberID= document.getElementById('<%= TrackClicks.ClientID %>');
I am using document.getElementById in another instance on the same page without problem. But in this case it always comes back with null for the id.

So I found this function to list every tagName on the document. I modified it to list every ID on the document and I call this function where I'm trying to get the element ID. And it shows every ID is undefined. You can see a few lines of that response at the end of this post.

Expand|Select|Wrap|Line Numbers
  1. function findhead1()
  2. {
  3.     var tag, tags;
  4.     tags = "The ClientIDs in the page are:"
  5.     for(i = 0; i < document.all.length; i++)
  6.     {
  7.   //      tag = document.all(i).tagName;
  8.         tag= document.all(i).id+document.all(i).ClientID
  9.         tags = tags + "\n" + tag;
  10.     }
  11.     document.write(tags);
  12. }
  13.  
What's causing this?

Thanks,
Jim

Here's some of the document.write output
l00_The ClientIDs in the page are: undefined undefined ctl00_Head1undefined undefined undefined undefined undefined undefined undefined undefined ctl00_Body1undefined aspnetFormundefined undefined __EVENTTARGETundefined __EVENTARGUMENTundefined ctl00_PageContent_ProjectsTabContainer_ClientState undefined __LASTFOCUSundefined __VIEWSTATEundefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctpageLeftCoordinateundefined ctl00_pageTopCoordinateundefined ctl00_PageSettingsundefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctl00__PageHeader__Logoundefined undefined ctl00__PageHeader__LoginoutButtonundefined ctl00__PageHeader_UserNameLabelundefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctl00__MenuV_MultiLevelMenuundefined undefined undefined ctl00__MenuV_MultiLevelMenun0undefined undefined undefined undefined undefined undefined undefined ctl00__MenuV_MultiLevelMenun0Itemsundefined undefined undefined ctl00__MenuV_MultiLevelMenun1undefined undefined undefined undefined undefined undefined undefined undefined ctl00__MenuV_MultiLevelMenun0ItemsUpundefined undefined ctl00__MenuV_MultiLevelMenun0ItemsDnundefined undefined ctl00__MenuV_MultiLevelMenu_SkipLinkundefined undefined undefined undefined undefined undefined undefined undefined StartOfPageContentundefined ctl00_PageContent_UpdatePanel1_UpdateProgress1unde fined undefined undefined undefined ctl00_PageContent_UpdatePanel1undefined ctl00_PageContent__clientSideIsPostBackundefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectsRecordControlPanelExtend er_ClientStateundefined ctl00_PageContent_ProjectsRecordControlIconundefin ed undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectsRecordControlCollapsible Regionundefined undefined undefined undefined undefined ctl00_PageContent_ProjectsRecordControlPanelundefi ned undefined undefined undefined undefined ctl00_PageContent_NewProjectundefined undefined undefined ctl00_PageContent_ProjectNameundefined ctl00_PageContent_ProjectNameTextBoxMaxLengthValid atorundefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_HiddenProjectIDTextBoxMaxLengthV alidatorundefined undefined undefined ctl00_PageContent_PublicUseundefined undefined undefined ctl00_PageContent_WordWrapundefined undefined undefined ctl00_PageContent_Activeundefined undefined undefined ctl00_PageContent_Expiredundefined undefined undefined undefined undefined undefined ctl00_PageContent_ExpirationDateundefined undefined undefined ctl00_PageContent_ExpirationDateTextBoxMaxLengthVa lidatorundefined undefined undefined ctl00_PageContent_Deletedundefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectIDRequiredFieldValidatoru ndefined ctl00_PageContent_ProjectIDTextBoxMaxLengthValidat orundefined undefined undefined ctl00_PageContent_BeginTextPosundefined undefined undefined ctl00_PageContent_MessyTextFileundefined ctl00_PageContent_MessyTextFileTextBoxMaxLengthVal idatorundefined ctl00_PageContent_UIMessages_txtundefined undefined undefined ctl00_PageContent_ProjectNotesundefined ctl00_PageContent_ProjectNotesTextBoxMaxLengthVali datorundefined undefined undefined ctl00_PageContent_ClickableTextBoxundefined ctl00_PageContent_TextBoxWatermark_ClientStateunde fined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_MessyTextundefined ctl00_PageContent_MessyTextTextBoxMaxLengthValidat orundefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectsTabContainerundefined ctl00_PageContent_ProjectsTabContainer_headerundef ined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_tabundefined undefined undefined __tab_ctl00_PageContent_ProjectsTabContainer_Colum nlayoutTabPanelundefined ctl00_PageContent_ProjectsTabContainer_ValidationT abPanel_tabundefined undefined undefined __tab_ctl00_PageContent_ProjectsTabContainer_Valid ationTabPanelundefined ctl00_PageContent_ProjectsTabContainer_ClicksTabPa nel_tabundefined undefined undefined __tab_ctl00_PageContent_ProjectsTabContainer_Click sTabPanelundefined ctl00_PageContent_ProjectsTabContainer_ColumndataT abPanel_tabundefined undefined undefined __tab_ctl00_PageContent_ProjectsTabContainer_Colum ndataTabPanelundefined ctl00_PageContent_ProjectsTabContainer_bodyundefin ed ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanelundefined undefined undefined undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnlayoutTableControlCollapsibleRegio nundefined undefined undefined undefined undefined tableContainerundefined undefined undefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnlayoutToggleAllundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnNumberLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_DelimiterBeginningLabelundefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_DelimiterEndingLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_DelimiterBIncludedinPasteLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_DelimiterBIncludedinCutLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_FixedLengthLabelundefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_MaximumSizeLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_TrimBlanksLabelundefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_AutoClearLabelundefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ValueCrossesCrLfLabelundefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ActiveLabel3undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_NotesLabel1undefined undefined undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnlayoutTableControlRepeater_ctl00_C olumnlayoutRowViewButtonundefined undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnlayoutTableControlRepeater_ctl00_C olumnlayoutRecordRowSelectionundefined undefined undefined undefined undefined undefined ctl00_PageContent_ProjectsTabContainer_Columnlayou tTabPanel_ColumnlayoutTableControlRepeater_ctl00_C olumnNumber1undefined undefined undefined
Dec 24 '11 #1
13 1984
Dormilich
8,658 Expert Mod 8TB
I'm having trouble getting this simple thing to work
Expand|Select|Wrap|Line Numbers
  1. ClickNumberID= document.getElementById('<%= TrackClicks.ClientID %>');
- what does this code look like in the browser?
- when do you call this piece of code?
- does this ID exist in your HTML?

Expand|Select|Wrap|Line Numbers
  1. tag= document.all(i).id+document.all(i).ClientID
- there is no attribute ClientID (at least not in HTML)
- when do you call this function?
Dec 24 '11 #2
jimatqsi
1,271 Expert 1GB
I have a textbox defined as so:
Expand|Select|Wrap|Line Numbers
  1. <asp:textbox id="ClickableTextBox" runat="server" cssclass="field_input" onclick="MessyTextClick()" width="800px" textmode="MultiLine" tooltip="Unprocessed Messy Text" columns="6" rows="8"></asp:textbox> 
  2. <asp:textboxwatermarkextender id="TextBoxWatermark" runat="server" targetcontrolid="ClickableTextBox" watermarktext="Paste your messy text here or enter the source file location above" watermarkcssclass="field_input" />
When clicked, it runs this script function, "MessyTextClick()"
That function needs to get the value from text box with ID="TrackClicks"

I am getting into the function MessyTextClick but the script apparently cannot find the IDs of the objects on the page.

I've used very similar code at another place on the page. When the box in that instance is clicked, the box turns red and a help message is displayed in another textbox.The only major difference is TrackClicks and ClickableTextBox exist in the top, main part of the form and the working textboxes are in a subpanel/subform within the main form.

Jim
Dec 24 '11 #3
Dormilich
8,658 Expert Mod 8TB
what is the code for that function? (as seen in the browser, of course)
Dec 24 '11 #4
jimatqsi
1,271 Expert 1GB
Here is the current code from MessyTextClick()
Expand|Select|Wrap|Line Numbers
  1. function MessyTextClick()
  2. {
  3.    var colID = document.getElementById("<%=Col01Label.ClientID%>");
  4.    var clickID = document.getElementById("<%=ActionGuideDescription_label.ClientID%>");
  5.     clickID.innerHTML=clickID.innerHTML+", Fill "+colID.innerHTML ;
  6.     alert ("ClickNo=?");
  7.  
  8.     // findhead1();
  9.  
  10.   // ClickNumberID  = document.getElementById("ClickCounter_hidden");
  11.    ClickNumberID= document.getElementById('<%=TrackClicks.ClientID%>');
  12.     if (ClickNumberID==null) 
  13.     {
  14.         ClickNumberID = document.getElementById("TrackClicks").id;
  15.     }
  16.    if (ClickNumberID==null)
  17.    {
  18.        ClickNumberID=document.getElementsByTagName("TrackClicks.tagName");
  19.    }
  20. //      alert("ClickNumberID.innerHTML "+ClickNumberID.innerHTML)
  21.        if (ClickNumberID!=null)
  22.     {
  23.         iClickNo = parseInt(ClickNumberID.value) ; // Text?   innerHTML
  24.     }
  25.     alert ("ClickNo="+iClickNo);
  26.     if (iClickNo<=0)
  27.     {
  28.         iClickNo=01;
  29.     }
  30.    PageMethods.GetClickAction(iClickNo, ProcessClick);  ////////////////////////////////////////////
  31. }
  32.  
Dec 24 '11 #5
Dormilich
8,658 Expert Mod 8TB
if that’s what shows up in your browser, then your ASP is not working.
Dec 24 '11 #6
jimatqsi
1,271 Expert 1GB
I've added some code to try other objects but I always get the same result. Yet those first 3 lines in another function in the same script works okay, but in this script they fail because the IDs cannot be found.

Jim
Dec 24 '11 #7
jimatqsi
1,271 Expert 1GB
Right, sorry you did say in my browser ... okay, so I am now viewing the page source in my browser. It's over 3300 lines of code. If I search for the name of my javascript function MessyTextClick it is not found. What does that mean?

Jim
Dec 24 '11 #8
Dormilich
8,658 Expert Mod 8TB
maybe it’s in an external file? can I have a link to your page?
Dec 24 '11 #9
jimatqsi
1,271 Expert 1GB
It's not yet published. All the javascript is within the page.

I was asleep, I didn't navigate to the right page before getting the source code. Here's what is in the browser for the function:

Expand|Select|Wrap|Line Numbers
  1. function MessyTextClick()
  2. {
  3.    var colID = document.getElementById("ctl00_PageContent_ProjectsTabContainer_ColumndataTabPanel_Col01Label");
  4.    var clickID = document.getElementById("ctl00_PageContent_ProjectsTabContainer_ColumndataTabPanel_ActionGuideDescription_label");
  5.     clickID.innerHTML=clickID.innerHTML+", Fill "+colID.innerHTML ;
  6.     alert ("ClickNo=?");
  7.  
  8.     // findhead1();
  9.  
  10.   // ClickNumberID  = document.getElementById("ClickCounter_hidden");
  11.    ClickNumberID= document.getElementById('ctl00_PageContent_ProjectsTabContainer_ColumndataTabPanel_TrackClicks');
  12.     if (ClickNumberID==null) 
  13.     {
  14.         ClickNumberID = document.getElementById("TrackClicks").id;
  15.     }
  16.    if (ClickNumberID==null)
  17.    {
  18.        ClickNumberID=document.getElementsByTagName("TrackClicks.tagName");
  19.    }
  20. //      alert("ClickNumberID.innerHTML "+ClickNumberID.innerHTML)
  21.        if (ClickNumberID!=null)
  22.     {
  23.         iClickNo = parseInt(ClickNumberID.value) ; // Text?   innerHTML
  24.     }
  25.     alert ("ClickNo="+iClickNo);
  26.     if (iClickNo<=0)
  27.     {
  28.         iClickNo=01;
  29.     }
  30.    PageMethods.GetClickAction(iClickNo, ProcessClick);  ////////////////////////////////////////////
  31. }
Dec 24 '11 #10
Dormilich
8,658 Expert Mod 8TB
you have that long IDs?

"TrackClicks.tagName" seems to be a somewhat strange ID, are you sure it exists?
Dec 24 '11 #11
jimatqsi
1,271 Expert 1GB
No, that's not an ID, it's another property. The findhead() function I listed in an earlier post was originally written to list all the tagNames of objects on the page. I copied and changed it to show me the IDs. I thought I would try to look up this object by tagName but that instruction looks silly to me now.

I've been working on this for 2 days. More and more crud is creeping into it as I try variations of the same thing.

Here's my revised version of the findhead function I found on the 'Net.


Expand|Select|Wrap|Line Numbers
  1. function findhead1()
  2. {
  3.     var tag, tags;
  4.     tags = "The ClientIDs in the page are:"
  5.     for(i = 0; i < document.all.length; i++)
  6.     {
  7.   //      tag = document.all(i).tagName;
  8.         tag= document.all(i).id+document.all(i).ClientID
  9.         var strN=document.all(i).id+document.all(i).tagName
  10.         //x=document.getElementById("myHeader")
  11.         if (strN.indexOf("TrackClicks")>0)
  12.         {
  13.             alert("Found ClientID:"+document.all(i).id+document.all(i).ClientID);
  14.         }
  15.         tags = tags + "\n" + tag;
  16.     }
  17.     document.write(tags);
  18. }
Dec 24 '11 #12
Dormilich
8,658 Expert Mod 8TB
can’t really say anything to it since it is IE-only syntax.
Dec 24 '11 #13
jimatqsi
1,271 Expert 1GB
@Dormilich
Oh, really? I have to redo it then, I want it to be browser agnostic <sigh> ... I think my original problem had to do with one instruction referencing .ClientID when it should have been .ID. After Christmas I'll start over. Thanks very much for your help.

Jim
Dec 24 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
3
by: pareshgoel | last post by:
class B { virtual ~B(); } class D:public B { virtual ~D(); }
19
by: E. Robert Tisdale | last post by:
In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C 9 standard. Specifically, it is *not* true that "anything can...
12
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>>...
33
by: dragoncoder | last post by:
Hi all, Does the following code invoke undefined behaviour ? $ cat a1.cc #include <iostream> #include <limits> int main() { int a = INT_MAX/2;
14
by: avsharath | last post by:
In "Bjarne Stroustrup's C++ Style and Technique FAQ" at: http://www.research.att.com/~bs/bs_faq2.html#evaluation-order for the statement: f(v,i++); he says that "the result is undefined...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
12
by: Rajesh S R | last post by:
Can anyone tell me what is the difference between undefined behavior and unspecified behavior? Though I've read what is given about them, in ISO standards, I'm still not able to get the...
33
by: coolguyaroundyou | last post by:
Will the following statement invoke undefined behavior : a^=b,b^=a,a^=b ; given that a and b are of int-type ?? Be cautious, I have not written a^=b^=a^=b ; which, of course, is undefined....
8
by: Aftabpasha | last post by:
In a function call like printf("%d,..",++i,++i,..) can we consider every ++i as a Full Expression? And if it is a full expression, it means there is a sequence point after every ++i. So,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.