PDA

View Full Version : Change Form Value



kaos
11-19-2009, 01:36 AM
Hi i'm trying to me a simple link to us form.


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

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

boogyman
11-19-2009, 11:37 PM
Start by not using Tables for layout.

Review the following sites for more information
http://howtocreate.co.uk
www.w3.org/MarkUp/#html4

prasanthmj
11-20-2009, 07:19 AM
Corrected 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 (http://www.javascript-coder.com/javascript-form/getelementbyid-form.htm)

get the value of a form element using JavaScript (http://www.javascript-coder.com/javascript-form/javascript-get-form.htm)

set the value of a form element using Javascript (http://www.javascript-coder.com/javascript-form/javascript-form-value.htm)

kaos
11-23-2009, 01:23 AM
@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?