title: Filling form fields with jquery
body: <p>So I have a form that will be used for both inserting and editing data from MySQL.
  I thought that instead of writing two forms, I'd write just one, that will be used for both purposes. So when it's for inserting new data, its fields (inputs etc) are obsiously empty. But when it's for editing existing data, I have Jquery for filling the fields with .val().</p>
  
  <p>Like this: </p>
  
  <pre><code>function formSetup(form_name, array_fields)
  {
      $(document).ready(function(){
          var selector;
          for(var key in array_fields)
          {
              selector = "form[name=" + form_name + "] [name=" + key + "]";
              //alert(selector);
              $(selector).val(array_fields[key]);
          }
      });
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>var fieldsArray = new Array();
  fieldsArray["field1"] = "data read from Myqsl php";
  fieldsArray["field2"] = "data read from Myqsl php";
  //etc
  </code></pre>
  
  <p>Btw, PHP does the job of telling my page whether this form is supposed to insert or edit data, so this javascript function will only be called by php when there is $_GET["action"]=="edit".</p>
  
  <p>What I want to know is, is this the best approach for doing that kind of thing?
  Is there a standard way for doing this?</p>