link with dynamic value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

link with dynamic value

Post by shiznatix »

i have a link but i want to add a value on to it with javascript with a onclick event. heres the idea

Code: Select all

<input type="text" name="other" size="3">

<a href="?go=b_funk&other=">Click ME!</a>
when you click that link, i want the value of the text box to be put into the end of the link so the get value would be the value that was in the text box.

how would i go about doing this? don't tell me there are so many other better ways to do somtin like this because i am struggling to fix these problems in this project i got in at the very end and this is the only real way to do this.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

make a javascript function that takes the base URL and the string to append to it as params

Code: Select all

function jump2url (base, append) {
   window.location=base+append;
}
not tested but that's the general idea
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

n00b Saibot to rescue :wink:

Code: Select all

<form name="frm">
<input type="text" name="other" size="3">
</form>

<a href="?go=b_funk&other=" onclick="this.href = this.href.substr(0, 17) + document.frm.other.value">Click ME!</a>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

many thanks. works just fine
Post Reply