Occasionally, I visit URLs that have page numbers indicated in the HREF. As these page numbers change, keeping track of the last one visited becomes a challenge. Cutting and pasting into a text file is a temporary solution; therefore, I intend to replace it with a local HTML page that can be updated using JavaScript. Below is an example of what I have created:
<script type="application/javascript">
function update(n,newvalue) {
var link = document.getElementById('l' + n);
var href = link.getAttribute('href', 2);
var textfield = document.getElementById('p' + n);
var parts = new Array();
parts = href.split('-');
parts[1] = 'p' + newvalue;
textfield.setAttribute('value', newvalue);
var newhref = parts.join('-');
link.setAttribute('href',newhref);
}
</script>
<form>
<dl>
<dt><a target="_blank" id="l1" href="http://foobar.org/t5-p8-data.html">Task 5 Data<a></dt>
<dd>Page: <input type="text" id="p1" value="8" onChange="update(1,this.value)" /> </dd>
</dl>
</form>
</html>
After entering a new value in the text field and tracing through with Firebug, it appears to work correctly - the link's href value and the text field's value are changed within the DOM. However, upon exiting the function, they revert back to their original values on the page. What could be causing this issue?