pass value javascript variable to ajax variable??
Code:
<script>
var time=1;
function timeHere() {
time = time + 1;
finalTime = time / 10;
}
function sayTime() {
finalTime = time / 10;
}
</script>
<body onload='window.setInterval("timeHere()", 100)' onunload="sayTime()">
</body>
I want to get the time i.e. value of finalTime in ajax varable.
Not using cookie, becoz it gives value on same page but after reloading page am using this to javaScript to php
How i get this without reloading or refreshing page...
so question is How to save value of variable in javaScript to ajax variable??
means save value of finalTime in ajax variable
How to do this??
Help posting value from ajax call
Your recent comment is exactly what I need to figure out. Please take a look.
I have a form that generates a part number based upon a series of selection boxes.
http://brinsterinc.com/east/inventory_test.php
I want to pass the part number as a hidden field in a second form that I am going to add to the page. That form will email the part number along with name, email address, etc.
How can I access the part number so that it can be passed as an invisible field?
The code that displays the part number is...
Code:
<span name="myspan" id="myspan" style="border:1px solid #000000; padding:2px;"></span>
and the ajax script is...
Code:
<script type="text/javascript" language="javascript">
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('myspan').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}
function get(obj) {
var poststr = "s=" + document.getElementById("s").value + "&it=" + document.getElementById("it").value + "&id=" + document.getElementById("id").value + "&ot=" + document.getElementById("ot").value + "&od=" + document.getElementById("od").value + "&l=" + document.getElementById("l").value ;makePOSTRequest('post.php', poststr);
}
</script>