Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write text from an input field into a link

    Hello, I'm a JavaScript Newbie. What I would like to do sounds simple enough, but somehow I can't find anything on the net how to do it.

    I'd like to take the text entered into an input field and then on the fly write it into a link. Is that possible somehow? I know how to do it vice versa - writing the text of something into an input field with document.getElementById("textfield").value = "", but how can I do it the other way around?

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    document.getElementById('linkId').innerHTML = document.formname.elname.value;

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thnx, but not entirely what I'm looking for. I'm trying to construct a link which already has static parts, and the content of the input is supposed to be the dynamic part.

    I got this right now, but it's obviously not working:

    Code:
    onblur="document.getElementById('linkid').getAttribute('href') = document.write('http://www.myurl.com?keyword=');document.form.input.value;document.write('&other=variable');"
    What am I doing wrong?

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    This should do it
    Code:
    onblur="document.getElementById('linkid').href = 'http://www.myurl.com?keyword='+document.form.input.value+'&other=variable';"
    *EDIT* Thanks abduraooft you're correct
    Last edited by ninnypants; 08-08-2008 at 06:33 PM.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    .document.getElementById('linkid').getAttribute('href') =
    shouldn't it be
    Code:
    document.getElementById('linkid').href =
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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