Using php & jquery to post data from textboxes to text (csv) file and verify this by reading back to different textboxes on same webpage -


very simply, browser style ui, i'm trying read 2 parameters (provided user) in 2 textboxes, save them in plain text file (specifically csv that's not important) on server not stopping there, ensure these has saved correctly, , feedback user, want read newly saved parameters file 2 other textboxes on same page.

when page loads, jquery populates "currently saved settings" textboxes values read in server csv file using php. when enter new values , click [submit] button save these values, server file gets updated successfully.

and next steps problem arises, can use php read newly stored values in server file , "alert" them check correct jquery lines update "currently saved settings" not update. have refresh webpage these textboxes update. should "alerts" display correct (newly saved) values point works fine it's following 2 jquery lines work on page load don't seem executed @ point.

hopefully there's dead simple i'm missing here.

(the csv file 2 parameters used complete separate , unrelated piece of software.)

help appreciated.

php file follows:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title>system settings</title>     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />     <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>     <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>   <?php     $systemsettings = explode(",",file_get_contents('data/settings.csv'));         ?>  <script type="text/javascript">     $(document).ready(function () {                                 $("#txtstoredparam1").val("<?php echo $systemsettings[0] ?>");         $("#txtstoredparam2").val("<?php echo $systemsettings[1] ?>");          $("#btnsavesettings").button();      });              </script>  </head> <body>  <?php if(isset($_post['submit']))  {     $file = "data/settings.csv";      $handle = fopen($file, 'w');     $data = $_post['param1'] . "," . $_post['param2'];      fwrite($handle, $data);     fclose($handle);     $systemsettings = explode(",",file_get_contents('data/settings.csv'));  ?>     <script>        // alert("<?php echo $systemsettings[0] ?>");        // alert("<?php echo $systemsettings[1] ?>");          $("#txtstoredparam1").val("<?php echo $systemsettings[0] ?>");          $("#txtstoredparam2").val("<?php echo $systemsettings[1] ?>");     </script> <?php } ?>   <form id="form" method="post" action="<?php echo $_server['php_self']; ?>" name="settingsform" target="iformresponse"> <h2>parameter 1:</h2> <input id="txtparam1" type="text" name="param1" /> <h2>parameter 2:</h2> <input id="txtparam2" type="text" name="param2" />  <p>&nbsp;</p>  <p><input id="btnsavesettings" type="submit" value="save settings" name="submit" /></p>  <p>&nbsp;</p>  <h3> saved settings: </h3> <p> <label id="lblparam1">parameter 1: </label><input id="txtstoredparam1" type="text" name="storedparam1" /> <label id="lblparam2">parameter 2: </label><input id="txtstoredparam2" type="text" name="storedparam2" /></p>  </form>  <iframe name="iformresponse" width="300" height="200" style="display:none;"></iframe>  </body> </html> 

your first script block used $(document).ready() whereas second not. therefore, second block runs first , overridden second.

delete second block , move code first block end of page have 1 script block reused in both cases.

but since using forms , php, why not set value of input?

<input id="txtparam2" type="text" name="param2" value="<?php echo $systemsettings[0];?>" /> 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -