Jump to content

id tag


ownage
 Share

Recommended Posts

if i do this

<form><input type="password" value="" id="tfield" / ><br /><input type="button" value="Submit" onclick="chooseme()" /></form>

and i make a fuction do this

function chooseme(){var a = document.getElementById("tfield").document.write(a)}

why wouldnt it work? also the part after getElementById("tfield") can i put functions such as tfield.funcname()

Link to comment
Share on other sites

It wouldn't work because, in the HTML DOM, the input element doesn't have a document element. There are (at least) three ways to accomplish what you are trying:

// Option 1var a = document.getElementById("tfield");document.write(a.value);// Option 2var a = document.getElementById("tfield").value;document.write(a);// Option 3document.write(document.getElementById("tfield").value);

Check out the HTML DOM tutorial: http://www.w3schools.com/htmldom/default.asp

Link to comment
Share on other sites

do i leave the value field as value? where u have used value
Yes. If you have the following HTML:
<input type="text" value="this is some text" id="tfield" />

You can get at each of the properties (and more) using the DOM:

var input = document.getElementById("tfield");var type = input.type; // this will be "text"var value = input.value; // this will be "this is some text"var id = input.id; // this will be "tfield"

Here's the part of the HTML DOM tutorial which speaks about inputs of type "password":http://www.w3schools.com/htmldom/dom_obj_password.asp

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...