Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


javascript getElementsByTagName() in conjunction with AJAX (javascript)

javascript getElementsByTagName() in conjunction with AJAX (javascript)

javascript getElementsByTagName() in conjunction with AJAX (javascript)


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++)

CODE --> javascript

   var inputField = elemInputs[i].name;
   if(inputField.indexOf('chkLot') == 0) {
    // --- Here I was Previously able to do what I need to do ---
    // --- NOW 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.


RE: javascript getElementsByTagName() in conjunction with AJAX (javascript)

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

RE: javascript getElementsByTagName() in conjunction with AJAX (javascript)

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.

RE: javascript getElementsByTagName() in conjunction with AJAX (javascript)

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

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?


RE: javascript getElementsByTagName() in conjunction with AJAX (javascript)

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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close