Results 1 to 4 of 4

Thread: Change Form Value

  1. #1
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

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

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Start by not using Tables for layout.

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

  3. #3
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    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

  4. #4
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •