Hi, I'm trying to add a form on my website so that the url and page title can be copied (basically so that anyone can copy a link to a specific page). So what I need to do is create the form somewhere on the page with a href and title statement but for javascript to fill in the url and title fields. Can anyone point out how to do this? Thanks for any help.
Your JavaScript should be something like this <script type="text/javascript"> function init() { document.getElementById("url").value = window.location.href; document.getElementById("title").value = document.title; } window.onload=init; </script> HTML: And the HTML form <form> URL: <input type="text" value="" id="url" readonly="readonly" /> Title: <input type="text" value="" id="title" readonly="readonly" /> </form> HTML:
Thanks for the help. Is there anyway it can altered slightly so that the form is formatted for the link code already, like this: <form> URL: <a href="<input type="text" value="" id="url" readonly="readonly" />"><input type="text" value="" id="title" readonly="readonly" /></a> </form> Code (markup): Thanks again for your help, it's much appreciated.
This will set the links anchor text to the title of the page while referencing the link to the current page: <script type="text/javascript"> function init() { document.getElementById("url").href = window.location.href; document.getElementById("title").innerHTML = document.title; } window.onload=init; </script> HTML: <a href="" id="url"><span id="title"></span></a> HTML: