Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery/Ajax/Json - Display respective values on submit for inputs with same class name
    primarykey
    data
    text
    <p>What I want to do is: When each button is pressed, show it's respective value. Right now the value returned is always "1". The json.php file will eventually be used to update records in a database. </p> <p>Any help would be greatly appreciated. Thanks!</p> <p>Here's the json.php file:</p> <pre><code>&lt;?php if(isset($_POST['hidden'])) { $data['value'] = $_POST['hidden']; } echo json_encode($data); ?&gt; </code></pre> <p>And here's the HTML:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;jQuery/Ajax - Display respective values on submit for inputs with same class name&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("form[name=form1]").submit(function() { $.post("json.php", { hidden : $(".check").siblings(".hidden").val() }, function(data){ alert(data.value); }, "json"); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" name="form1" method="post"&gt; &lt;input type="submit" class="check" value="check1" /&gt;&lt;br /&gt; &lt;input type="submit" class="check" value="check2" /&gt;&lt;br /&gt; &lt;input type="submit" class="check" value="check3" /&gt; &lt;input class="hidden" name="hidden" type="hidden" value="1" /&gt; &lt;input class="hidden" name="hidden" type="hidden" value="2" /&gt; &lt;input class="hidden" name="hidden" type="hidden" value="3" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload