javascript - Having issue passing a localStorage value to an input field -


okay guys, i'm having issue trying pass value stored in local storage on input field. found other thread, (pass javascript variable value input type hidden value) showed how it, it's still not working me , have no idea i'm doing wrong. entire code down below, have separated out make easier parts matter.

    <html>     <head> <title>location details</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script type="text/javascript"> 

this i'm trying pass stored values fields have not luck.

    document.getelementbyid("plat").value = localstorage.latitude;     document.getelementbyid("plon").value = localstorage.longitude;      function fileselected() {                     var file = document.getelementbyid("fileupload").files[0];         if (file) {             var filesize = 0;             if (file.size > 1024 * 1024) {                 filesize = (math.round(file.size * 100 / (1024 * 1024)) / 100).tostring() + 'mb';             }             else {                 filesize = (math.round(file.size * 100 / 1024) / 100).tostring() + 'kb';             }              document.getelementbyid("filename").innerhtml = 'name: ' + file.name;             document.getelementbyid("filesize").innerhtml = 'size: ' + filesize;             document.getelementbyid("filetype").innerhtml = 'type: ' + file.type;         }     }      function uploadfile() {         var id = new formdata();         id.append("fileupload", document.getelementbyid("fileupload").files[0]);         var xhr = new xmlhttprequest();         xhr.upload.addeventlistener("progress", uploadprogress, false);         xhr.addeventlistener("load", uploadcomplete, false);         xhr.addeventlistener("error", uploadfailed, false);         xhr.addeventlistener("abort", uploadcancelled, false);         xhr.open("post", "snap.php");         xhr.send(id);     }      function uploadprogress(evt) {         if (evt.lengthcomputable) {             var percentcomplete = math.round(evt.loaded * 100 / evt.total);             document.getelementbyid("progressnumber").innerhtml = percentcomplete.tostring() + '%';         }         else {             document.getelementbyid("progressnumber").innerhtml = 'unable compute';         }     }      //==================================================================     // these events raised when server sends response     //==================================================================     function uploadcomplete(evt) {          alert(evt.target.responsetext);     }      function uploadfailed(evt) {         alert("therew error attempting upload file.");     }      function uploadcancelled(evt) {         alert("the upload has been cancelled user or browser dropped connection.");     } </script> </head> <body>      <div>     <form id="form1" enctype="multipart/form-data" method="post" action="scripts/snap.php"> 

here input fields. fine me.

       <p>             <input id="plat" type="text" value="" />             <input id="plon" type="hidden" value="" />         </p>         <div class="row">             <label for="fileupload">select image upload</label><br />             <input type="file" name="fileupload" id="fileupload" onchange="fileselected();" />         </div>         <div id="filename"></div>         <div id="filesize"></div>             <div id="filetype"></div>         <div class="row">             <input type="button" onclick="uploadfile()" value="upload" />         </div>         <div id="progressnumber"></div>     </form> </div> </body> </html> 

try code calling script before dom content loads:

    document.addeventlistener('domcontentloaded', function () {         document.getelementbyid("plat").value = localstorage.latitude;         document.getelementbyid("plon").value = localstorage.longitude;     }, false);       function fileselected() {         var file = document.getelementbyid("fileupload").files[0];         if (file) {             var filesize = 0;             if (file.size > 1024 * 1024) {                 filesize = (math.round(file.size * 100 / (1024 * 1024)) / 100).tostring() + 'mb';             }             else {                 filesize = (math.round(file.size * 100 / 1024) / 100).tostring() + 'kb';             }              document.getelementbyid("filename").innerhtml = 'name: ' + file.name;             document.getelementbyid("filesize").innerhtml = 'size: ' + filesize;             document.getelementbyid("filetype").innerhtml = 'type: ' + file.type;         }     }      function uploadfile() {         var id = new formdata();         id.append("fileupload", document.getelementbyid("fileupload").files[0]);         var xhr = new xmlhttprequest();         xhr.upload.addeventlistener("progress", uploadprogress, false);         xhr.addeventlistener("load", uploadcomplete, false);         xhr.addeventlistener("error", uploadfailed, false);         xhr.addeventlistener("abort", uploadcancelled, false);         xhr.open("post", "snap.php");         xhr.send(id);     }      function uploadprogress(evt) {         if (evt.lengthcomputable) {             var percentcomplete = math.round(evt.loaded * 100 / evt.total);             document.getelementbyid("progressnumber").innerhtml = percentcomplete.tostring() + '%';         }         else {             document.getelementbyid("progressnumber").innerhtml = 'unable compute';         }     }      //==================================================================     // these events raised when server sends response     //==================================================================     function uploadcomplete(evt) {          alert(evt.target.responsetext);     }      function uploadfailed(evt) {         alert("therew error attempting upload file.");     }      function uploadcancelled(evt) {         alert("the upload has been cancelled user or browser dropped connection.");     } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -