View Full Version : Write text from an input field into a link

08-08-2008, 05:05 PM
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?

08-08-2008, 05:16 PM
document.getElementById('linkId').innerHTML = document.formname.elname.value;

08-08-2008, 05:27 PM
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:

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?

08-08-2008, 05:38 PM
This should do it

onblur="document.getElementById('linkid').href = 'http://www.myurl.com?keyword='+document.form.input.value+'&other=variable';"
*EDIT* Thanks abduraooft you're correct

08-08-2008, 05:43 PM
.document.getElementById('linkid').getAttribute('href') = shouldn't it be
document.getElementById('linkid').href = ?