开发者

Populating data in the text fields using java scripts

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 ht开发者_C百科ml. I want to use only Java script.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜