Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript getElementsByTagName() in conjunction with AJAX (javascript)

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
0
0
US
Hello,

I have finally gotten my intended javascript function to launch within a ASP.Net webpage utilizing an Ajax UpdatePanel.
Just for a VB.Net FYI it took: ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), Guid.NewGuid().ToString(), "startUpScript()", True)​
Finding that was a challenge!

However now I have another issue regarding the execution of previously working code.

Previously I was able to 'look' for various Form objects by using the: getElementsByTagName("input");
That code still executes fine, but the results are now different.

var elemInputs = document.getElementsByTagName("input");
for(var i = 0; i < (elemInputs.length-1); i++)
JavaScript:
{
   var inputField = elemInputs[i].name;
   if(inputField.indexOf('chkLot') == 0) {
    // --- Here I was [u]Previously[/u] able to do what I need to do ---
    // --- [u]NOW[/u] the very same code no longer 'sees' any of these form objects ---
   }
}

Now that very same code no longer 'sees' the form's input objects, thereby preventing me from doing what I need to do.

If anyone has any suggestions/advice on what needs to be changed to enable this to work it would be greatly appreciated.

Thanks,
JRB-Bldr
 
Without knowing how or when this is running its hard to say anything concretely. Is the document.getElementsByTagName returning anything? i.e is elemInputs > 0

If it is > 0, what elements are in there?

You can place alerts to debug what the contents of your variables are.

alert("number of elements found is: " + elemInputs.length);





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Why are you subtracting 1 from the length argument in the for loop? That will stop the last element from being handled in the loop.

Also if the dom hasn't loaded by the time this runs (e.g. if you are trying to run this server side) you should not (typically) expect any results.

More info needed.
 
Thank you for your reply.

This code is running on the Page_Load() of the webpage
The var elemInputs = document.getElementsByTagName("input"); does indeed return 4 'finds', but they are not the intended form input objects

INTERESTING!!!
While looking to get you the elemInputs values, I see that the AJAX UpdatePanel javascript executes FIRST on the Page_Load.
The intended StartUpScript() only executes on a Page Refresh

So it looks as though I have 2 problems.
1. How do I get the intended javascript StartUpScript() to execute FIRST on Page_Load?
2. How do I get that same code to 'see' the Form Objects?

Thanks,
JRB-Bldr
 
OK, I am getting off-track due to the minutiae.

Let me back up and state what I need to occur and maybe that will clarify what I NEED instead of what I SAY I NEED.

With that in mind, lets cancel this posting and I'll start a new, hopefully more clearly presented post.

Thanks,
JRB-Bldr

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top