/    Sign up×
Community /Pin to ProfileBookmark

Change parameters in the URL based on values in two text boxes

Hi,

I am a starter. I am trying to change the parameters in a url based on the values in two text boxes using Javascript.

For example, URL: [url]http://www.webdeveloper.com/forum?value1=2210&value2=4321[/url]

Textbox1 – 2210
Textbox2 – 4321

Now, it works like this. If I enter different parameter values manually in the URL, the textbox values change automatically depending on that value. Now I am trying to get it done viceversa. i.e, If I enter values in the textbox, those values must automatically be updated in the URL and must reload on a button click.

It would be great if someone can help me with this.

Thank you,
dotaj

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangJul 02.2008 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>name value pairs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
var data=location.search;
data=location.search.substring(1); // remove the '?'
data=data.split('&');
var pairs={};
for(var i=0; i<data.length; i++){
var tmp=data[i].split('=');
pairs[tmp[0]]=tmp[1]; // name value pairs
}

window.onload=function() {
var f=document.form1;
f.value1.value=(pairs['value1'])? pairs['value1'] : '';
f.value2.value=(pairs['value2'])? pairs['value2'] : '';
};
</script>

<style type="text/css">

</style>

</head>
<body>
<form action="#" method="get" name="form1">
<div>
<input type="text" name="value1">
<input type="text" name="value2">
<button type="submit">submit</button>
</div>
</form>
</body>
</html>
×

Success!

Help @dotaj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...