My situation is this: I was able to write text from a form in a different html page. But what I wanted to do is create a link using only the text in that form.
Originally I used javascript, especially widget.preferences (a sort of method to save the changes made in the form) and the “var” tag:
<script>
addEventListener
(
'DOMContentLoaded',
function()
{
// get the var elements with an id and set their textContent to the corresponding widget.preferences
var vars = document.querySelectorAll( 'var[id]' );
for( var i=0,element=null; element=vars[i++]; )
{
element.textContent = widget.preferences[ element.id ];
}
},
false
);
</script>
</head>
<body>
<h1>Popup window</h1>
<p>Here is a list of preferences and their associated value:</p>
<ul>
<li><var id="foo"></var>
<li><var id="bar"></var>
<li><var id="baz"></var>
<li><var id="check"></var>
<li><var id="group1"></var>
<li><var id="myMultipleSelect"></var>
</ul>
</body>
But, as I said at the beginning, my goal is to make links using the text from the form on the other page. The form is as follows:
<fieldset>
<p>
<input id="text1" name="foo" type="text"></input>
<label for="text1">foo</label>
</p>
<p>
<input id="text2" name="bar" type="text"></input>
<label for="text2">bar</label>
</p>
<p>
<input id="text3" name="baz" type="text"></input>
<label for="text3">baz</label>
</p>
</fieldset>
I was not sure exactly what your question is, but for retrieving info from other pages with javascript, the answer is ajax.
There is an important caveat to this answer: To do this, your page and the page of the form you are trying to get data from need to be on the same domain. Modern browsers have security measures in place against XSS (cross site scripting), so you will not be able to get that information otherwise.
To get the contents of the form, make an ajax request for the page with that form on it, and then parse it’s html content as XML. You can then navigate through its DOM or use a framework like jQuery to extract the info you need for your links.
If you are new to ajax, try the w3c schools tutorial at http://www.w3schools.com/ajax/default.asp
If the webpage you are trying to access is on another domain, you may be out of luck. There are several proposed solutions for making friendly cross-site requests, such as microsofts XDR object, but there is no standard, so it will be quite a bit of work (if it is possible at all) to get that to work across the board.
Additionally, the restrictions against XSS are made in the browser where the js is currently running, so if you have access to a server-side language you can “shuttle” requests from a handler of some kind into your page.