php - Passing javascript value to html -
this related previous question: retrieving video database using php
on previous question pass speedmbps in javascript using ajax
form , $( "#speed" ).val( html ); expect return value unable embed html code in viewvideo.php.
i thought of different way pass speedmbps php.
passing value speedmbps html form can used method post sent data php file.
var imageaddr = "testimage.jpg"; var downloadsize = 2097152; //bytes window.onload = function() { var oprogress = document.getelementbyid("speed"); oprogress.value = "loading image, please wait..."; window.settimeout(measureconnectionspeed, 1); }; function measureconnectionspeed() { var oprogress = document.getelementbyid("speed"); var starttime, endtime; var download = new image(); download.onload = function () { endtime = (new date()).gettime(); showresults(); } download.onerror = function (err, msg) { oprogress.value = "invalid image, or error downloading"; } starttime = (new date()).gettime(); var cachebuster = "?nnn=" + starttime; download.src = imageaddr + cachebuster; function showresults() { var duration = (endtime - starttime) / 1000; var bitsloaded = downloadsize * 8; var speedbps = (bitsloaded / duration).tofixed(2); var speedkbps = (speedbps / 1024).tofixed(2); var speedmbps = (speedkbps / 1024).tofixed(2); return speedmbps; oprogress.value = "your connection speed is: <br />" + speedbps + " bps<br />" + speedkbps + " kbps<br />" + speedmbps + " mbps<br />"; document.getelementbyid("speed").value = speedmbps;
html code
<input type="text" id="speed" name="speed" value="">
viewvideo.php
$speed= $_post['speed'];
edited: when echo $speed in php file not echo.. no value pass javascript html form.
error on console unexpected end of input on
document.getelementbyid("speed").value = speedmbps;
your using return statement before setting data form.
document.getelementbyid("speed").value = speedmbps; return speedmbps;
Comments
Post a Comment