djairo
djairo

Reputation: 2743

Javascript get id

function check(id){
    var _id = document.getElementById(id);
    url = "test.php?check=1&id=" + _id;
}

i want the id in the url it's working but without the id that is in the check('123');

It's for an innerHTML to load something

hope you can help me with getting the id

Greetings

Upvotes: 1

Views: 10365

Answers (2)

Alex Rozanski
Alex Rozanski

Reputation: 38005

The document.getElementId() function returns an object value based on the identifier string (ID) that you supply; therefore if you have an element on your page with the id of foo then you call

document.getElementById("foo");

to return the object for that element, so that you can manipulate it (changing styles, or attributes etc).

If you want to insert the id into the URL of the test.php page, why not simply pass the identifier string of the element that you pass in with the function?:

function check(id){
    url = "test.php?check=1&id=" + id;
}

Then calling

check("123");

will set the url variable to test.php?check=1&id=123

Upvotes: 4

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

var _id = document.getElementById(id).id;

Upvotes: 2

Related Questions