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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use of document.body.getElementsByTagName('*')

Status
Not open for further replies.

tas2826

Programmer
Jul 6, 2005
26
0
0
US
Given the snippet below, let just say that elem[1] is a text input. How do I get the the type of input which would be "text", and the value that the text input contains?

Code:
var elem = document.body.getElementsByTagName('*');

var getIt = elem[1].id;

alert(getIt); //gives me the id
alert(getIt.type); //does not work, how do I get to type?
alert(getIt.value); //does not work, how do I get to value?

Thanks in advance,

Troy
 
Use try/catch

Code:
try {
   if (getIt.type == "text") {
      window.alert(getIt.id + " is a text field!");
      // do whatever
   }
} catch (e) {
   // this probably wasn't a text field, or trying to
   // do getIt.type threw a JavaScript exception. The
   // property `e.message` will tell you the error
   window.alert(e.message);
}

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
My bad

Code:
var elem = document.body.getElementsByTagName('*');

var getIt = elem[1].id;

alert(getIt); //gives me the id
alert(getIt.type); //does not work, how do I get to type?
alert(getIt.value); //does not work, how do I get to value?

should be this.

Code:
var elem = document.body.getElementsByTagName('*');

var getIt = elem[1];

if(getIt.type == "text")
{
   alert(getIt.id);
   alert(getIt.type);
   alert(getIt.value);
}

This should work correct? If its a standard input that is.

Thanks,
Troy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top