0

I have two html pages. from one html if I am clicking the id which i have made as a link I want the data associated with that to be populated into the other html page.Its like the id of an employee is being cliked and all te values associate dwith it like his name, address and gender should get populated in the text fields in the previous html table. Currently I am not using any DB. I have entered everything manually through html. I want to use only Java script.

2
  • I have two html pages. - Are they open in the same browser? Are they open at the same time? Are they within each other (like an iframe)? I think in that case you should change the title of your question to something like '... from one page to another'. Commented Mar 3, 2011 at 7:00
  • if I am clicking the id which i have made as a link - Or do you call the second page from the first one via a link? Then you should have a look at this. Commented Mar 3, 2011 at 7:03

1 Answer 1

1

If I understand your question: Yes, it can be done. (I don't know why you would want to do this without a database, but it is possible.) When you're making the links on your first page, make sure they contain the information you want in query string format like this:

<a href="secondpage.html?firstName=Bob&amp;lastName=Smith&amp;gender=M">Bob Smith</a>

Then on your second page, you can use JavaScript to parse window.location.search which is the query string that you passed from your first page. You can do this in many ways. Here is an example function that will let you extract variables from the query string. You could use it like this on the second page:

<script type="text/javascript">
var firstName = getParameterByName('firstName');
var lastName = getParameterByName('lastName');
var gender = getParameterByName('gender');
// now do something with those variables.
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

& is a special character in HTML. Don't forget to represent it as &amp;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.