Reputation: 101
I have the following function:
function loginUser(form){
try {
var user = Backendless.UserService.login(form.userid.value, form.pswrd.value);
if (user != null) {
window.location.href = "home.html";
} else
window.alert("Login failed");
}
} catch (e) {
window.alert("Login failed. " + e.message);
}
}
When I redirect to home.html
, the user object has various fields and I want to pass the value of user.credits
to an input box on the HTML page. How would I go about doing this?
This is what my HTML page looks like:
<div>Credits <input id="credits" type="text" class="input-block-level" placeholder="Credits" name="credits"></div>
Upvotes: 1
Views: 3857
Reputation: 101
Yes that worked thanks...
window.location.href = "home.html?credits="+user.credits;
and on your home.html :
document.getElementById('credits').value=getUrlVars()["credits"];
just needed the getUrlVars function as well
Upvotes: 0
Reputation: 1216
you coud do
window.location.href = "home.html?credits="+user.credits;
and on your home.html
:
document.getElementById('credits').value=getUrlVars()["credits"];
You may want to read up a bit on the concept of GET and POST variables. Also, notice this method is by no means safe: the user can easily manipulate the value.
A safer way would be to POST
the values, or, better still, to read them, for example via PHP, on the target page.
Upvotes: 3