title: Ajax - Modal - Passing Variable
body: <p>I know this has been asked a lot but after looking up for this for like 6 hours I can say I've tried everything that with my current knowledge (which isn't much) I can understand so I decided to come here and ask for help from the pros :).</p>
  
  <p>This button is also inside korisnik.php</p>
  
  <pre><code>&lt;button href="#myModal1" type="submit" role="button" data-toggle="modal" data-id="&lt;?php print $row['kime']?&gt;" class="open-myModal1"&gt;&lt;span class="glyphicon glyphicon-edit"/&gt;&lt;/button&gt;
  </code></pre>
  
  <p>This up top is a button that when clicked opens a modal and should pass a value to it, but it doesn't. After looking through a lot of posts on the net I found out easiest way is to send the variable back through AJAX so I used this:</p>
  
  <p>This is located in bottom part of korisnik.php</p>
  
  <pre><code>$(document).on("click", ".open-myModal1", function () 
  {
      var kime = $(this).data('id');
      $(".modal-body #kime").val( kime );
      $.post('korisnik.php', { 'kime': kime });
  });
  </code></pre>
  
  <p>Using <code>$kime = $_POST['kime']; print $kime;</code> in korisnici.php doesn't show the value at all but using <code>&lt;input type="text" name="kime" id="kime" value=""/&gt;</code> does. Problem with the one that works is that I still don't have the value needed inside a variable and can't use it to make a query based on the sent value.</p>
  
  <p>So my question is: </p>
  
  <p>How to make this work with ajax so I can get the value with $_POST['kime']?</p>
  
  <p>or</p>
  
  <p>How can I save the value inside the input field inside a variable? </p>
  
  <p>I hope I've been clear enough with my request. Either one of those works since I get what I want and that is a value saved inside a variable I can use for other things.</p>
  
  <p>Thanks for any help.</p>
  
  <p>EDIT: This is modal Code inside korisnik.php</p>
  
  <pre><code>            &lt;div class="modal fade" id="myModal1"&gt;
              &lt;div class="modal-dialog"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
                          &lt;button class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
                          &lt;center&gt;&lt;h4 class="modal-title"&gt;EDIT KORISNIKA&lt;/h4&gt;&lt;/center&gt;
                      &lt;/div&gt;&lt;!-- end header --&gt;
                      &lt;hr/&gt;
                      &lt;div class="modal-body"&gt;
                          &lt;!--&lt;input type="text" name="kime" id="kime" value=""/&gt;--&gt;
                          &lt;input type='text' name='kime' id='kime' value=''/&gt;
                          &lt;form class="form-horizontal" action='korisnik.php' method="post"&gt;
                          &lt;?php
                          $kime = $_POST['kime'];
                          $query = $db-&gt;prepare("SELECT * FROM korisnik WHERE kime = :kime");             
                          $query-&gt; execute(array(':kime' =&gt; $kime ));
                          $result = $query-&gt;fetch();
                          ?&gt;
                              &lt;table class="table table-striped"&gt; 
                                  &lt;tr&gt;&lt;th style="vertical-align:middle"&gt;&lt;center&gt;Korisničko Ime&lt;/center&gt;&lt;/th&gt;&lt;td&gt;&lt;input readonly class="form-control"  name="username" value="&lt;?php print $result['kime'] ?&gt;"id="username" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;
                                  &lt;tr&gt;&lt;th style="vertical-align:middle"&gt;&lt;center&gt;Ime&lt;/center&gt;&lt;/th&gt;&lt;td&gt;&lt;input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)"  name="name" id="name" value="&lt;?php print $result['ime'] ?&gt;"  type="text"&gt;&lt;/td&gt;&lt;/tr&gt;
                                  &lt;tr&gt;&lt;th style="vertical-align:middle"&gt;&lt;center&gt;Prezime&lt;/center&gt;&lt;/th&gt;&lt;td&gt;&lt;input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="surname" id="surname" value="&lt;?php print $result['prezime'] ?&gt;" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;
                                  &lt;tr&gt;&lt;th style="vertical-align:middle"&gt;&lt;center&gt;E-Mail&lt;/center&gt;&lt;/th&gt;&lt;td&gt;&lt;input class="form-control" name="email" id="email" onkeydown="emailk(this)" onkeyup="emailk(this)" onblur="emailk(this)" onclick="emailk(this)" value="&lt;?php print $result['email'] ?&gt;" type="email"&gt;&lt;/td&gt;&lt;/tr&gt;
                                  &lt;tr&gt;&lt;th style="vertical-align:middle"&gt;&lt;center&gt;Kredit&lt;/center&gt;&lt;/th&gt;&lt;td&gt;&lt;input class="form-control" name="kredit" id="kredit" onkeydown="alpha(this)" onkeyup="alpha(this)" onblur="alpha(this)" onclick="alpha(this)" value="&lt;?php print $result['kredit'] ?&gt;" type="number"&gt;&lt;/td&gt;&lt;/tr&gt;
                              &lt;/table&gt;
                      &lt;/div&gt;&lt;!-- end body--&gt;
                      &lt;hr/&gt;
                      &lt;div class="modal-footer"&gt;
                          &lt;input type="submit" class="btn btn-success pull-left" name="editk" value="Spremi Promjene" /&gt;
                          &lt;/form&gt;         
                          &lt;button class="btn btn-default pull-right" data-dismiss="modal" type="button"&gt;Odustani&lt;/button&gt;
                      &lt;/div&gt;&lt;!-- end footer --&gt;
                  &lt;/div&gt;&lt;!-- end modal-content --&gt;
              &lt;/div&gt;&lt;!-- end modal-dialog --&gt;
          &lt;/div&gt;&lt;!-- end modal --&gt;
  </code></pre>