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

 

Sorry, my bad, I missed a line there.

Link to comment
https://forums.phpfreaks.com/topic/41707-solved-find-all-tags/#findComment-202717
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
https://forums.phpfreaks.com/topic/41707-solved-find-all-tags/#findComment-203311
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
https://forums.phpfreaks.com/topic/41707-solved-find-all-tags/#findComment-203509
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.