/    Sign up×
Community /Pin to ProfileBookmark

passing variable to html through ajax

Dear all,

I get stuck in the middle and would like to get some help:

I got the first page, and have a javascript function (a.html)

<html>
<head>
<script type=”text/javascript” src=”js/a.js”></script>
</head>

<body>
<INPUT id=depaddress name=depaddress type=”textbox” class=”txtinput” size=30>
<input type=”submit” value=”Submit” onclick=”submitroute()”>
</body>

</html>

The code in a.js is as follows. I want to pass the value in depaddress to another html file (I don’t want to generate the html code on the drive as I have quite a lot of code and information in that html file):

function submitroute() {

var depaddress = document.getElementById(‘depaddress’).value;
var div = “apple”;
var url = “b.html”;
var myAjax = new Ajax.Updater(div, url, {method: ‘get’, evalScripts: true, parameters: ‘depaddress’});

}

b.html
<html>
<head>
<script type=”text/javascript”>
alert(depaddress);
</script>
</head>

<body>
<div id=”apple”>
</div>
</body>

</html>

I cannot get the value of depaddress in b.html. How can I pass the variable in the a.js to b.html? I don’t want to get involved the server-side programming language like php as I want to keep this in the client side.

Thanks heaps!

Kelvin

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJul 23.2011 — you will have read the url on the second page, get the variable and then display, it won't automatically show up in the next page (this is presuming your AJAX code is actually sending request to this second page
Copy linkTweet thisAlerts:
@kwytseauthorJul 23.2011 — I get what you mean, thanks a lot!
×

Success!

Help @kwytse 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...