-
Change Form Value
Hi i'm trying to me a simple link to us form.
Code:
<script>
var value1l = form.channel.value;
var value2 = form.ep.value;
var link-page = document.getElementById.link-page.value;
function link()
{
link-page = 'http://www.mydomain.com/dir/?playlist=dir2/' + value1 + '.xml&item=' + value2 + '';
}
</script>
Code:
<form id="link" name="link">
<table border=0>
<tr><td>Channel:</td><td><input type="text" id="channel" name="channel"></td></tr>
<tr><td>Episode:</td><td><input type="text" id="ep" name="ep"></td></tr>
<tr><td></td><td><input type="submit" value="Get URL" onClick="link()"></form></td></tr>
<tr><td>URL:</td><td><input type="text" id="link-page" name="link-page" style="width:300px"><input type="button" value="Select All"></td></tr>
</table>
Why isn't tis working?
-
Start by not using Tables for layout.
Review the following sites for more information
http://howtocreate.co.uk
www.w3.org/MarkUp/#html4
-
Corrected code
Code:
<script type="text/javascript">
function make_link()
{
var value1 = document.forms["link"].channel.value;
var value2 = document.forms["link"].ep.value;
var linkpage = document.getElementById("link-page");
linkpage.value = 'http://www.mydomain.com/dir/?playlist=dir2/' + value1 + '.xml&item=' + value2 + '';
}
</script>
<form id="link" name="link">
<table border=0>
<tr><td>Channel:</td><td><input type="text" id="channel" name="channel"></td></tr>
<tr><td>Episode:</td><td><input type="text" id="ep" name="ep"></td></tr>
<tr><td></td><td><input type="button" value="Get URL" onClick="make_link()"></form></td></tr>
<tr><td>URL:</td><td><input type="text" id="link-page" name="link-page" style="width:300px"><input type="button" value="Select All"></td></tr>
</table>
More info:
getElementById to get the elements in a form
get the value of a form element using JavaScript
set the value of a form element using Javascript
-
@prasanthmj
Thanks for the help... however, there's one problem: the correct value appear in the 'link-page' text box, but then i disappears in about 2 seconds. i found it has to do with the page refreshing with the values inputed in the adress bar like this:
domain.com/dir/?channel=inputed-value&ep=inputed-value&link-page=http:........... why is this?