Jump to content

[SOLVED] Find all tags


ldsmike88

Recommended Posts

When I do that it just gives me an alert box that says undefined - undefined. I can't make the alert box go away so every time I run it I have to close every IE window. It sounds like a good script, but how do I make it work right? Thanks!

 

Michael

Link to comment
Share on other sites

When I do that it just gives me an alert box that says undefined - undefined. I can't make the alert box go away so every time I run it I have to close every IE window. It sounds like a good script, but how do I make it work right? Thanks!

 

Michael

 

Sorry, my bad, I missed a line there.

Link to comment
Share on other sites

Well I tried that website but I couldn't find what I wanted. I created this sweet code with the help of another website. For some reason it wont get the textarea tag names unless I run it by itself. Why doesn't it work if I just include it in the array?

 

function getAllFormElements(formName){
var names = new Array();
var formTags = new Array('input','textarea','select','button');
for(var i = 0; i < formTags.length; i++){  
	formInputs = document.forms[formName].getElementsByTagName(formTags[i]);
	for(var i = 0; i < formInputs.length; i++){
		names.push(formInputs.item(i).name);
	}
}
formInputs = document.forms[formName].getElementsByTagName(formTags[1]);
for(var i = 0; i < formInputs.length; i++){
	names.push(formInputs.item(i).name);
}
for(var i = 0; i < names.length; i++){
	alert(names[i]);
}
}

Link to comment
Share on other sites

*shudder*

 

Why not go the simpler route (sorry, I though elements was a hash only, not a collection):

 

function getAllFormElements(formName){
var eForm = document.forms[formName];
for( var e = 0; e < eForm.elements.length; e++ ) {
  var el = eForm.elements[e];
  alert( el.name );
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.