Reputation: 1
I want couple of things happen simultaneously on keypress()
event, I got two pages, default.html where there is a input text box and another page.html with another input text box, Now what I need is that the moment a key is pressed to type a letter in to the input text box on default.html, keypress()
fires (I need this on keypress, not on keyup or keydown) and the 'letter' is captured
var c = String.fromCharCode(e.which);
and at same time page is redirected
document.location= "page.html"; return false;
to 'page.html' showing the 'letter' in the input text field which was typed on previous page. I have got incomplete code..
$(document).keypress(function(){
var c = String.fromCharCode(e.which);
document.location= "page.html";
return false;
}
});
don't know how to use var c here to show the value into the text field on next page(page.html).
javascript code on page.html...please correct and help with this code.. I picked it up from another post..I can see that the value typed on default.html page shows up in the address bar of page.html but does not show in the input text box, I know for sure I am doing it incorrectly. The code is mentioned below.
input field on default.html - <input id="search" type="text" name="searchbar">
input field on page.html - <input id="search2" type="text" name="searchbar2">
<script type="text/javascript">
var queryString = new Array();
$(function () {
if (queryString.length == 0) {
if (document.location.search.split('?').length > 1) {
var params = document.location.search.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var key = params[i].split('=')[0];
var value = decodeURIComponent(params[i].split('=')[1]);
queryString[key] = value;
}
}
}
if (queryString["name"] != null) {
var data = "<u>Values from QueryString</u><br /><br />";
data += "<b>Name:</b> " + queryString["name"];
$("#search1").html(data);
}
});
</script>
Upvotes: 0
Views: 1793
Reputation: 530
You can send the character in the query string like this:
document.location = "page.html?c=" + c;
Then, you can read it in JavaScript on page.html with
document.location.search
Upvotes: 1