Note that there are some explanatory texts on larger screens.

plurals
  1. POReference a hidden value in a form using jQuery/JavaScript
    primarykey
    data
    text
    <p>I am new to web development</p> <p>I have PHP delete function that I want to use to delete rows from a database table.</p> <pre><code>if($form_no==="delete" &amp;&amp; isset($_POST['id']) &amp;&amp; isset($_POST['form_no'])) { switch ($_POST['form_no']) { case 1:$table="employees"; break; default:break; } $query="DELETE from ".$table." where id=".$_POST['id']; mysql_query($query)or die( ' '.mysql_error().' '.$query); $message='deleted'; switch ($_POST['form_no']) { case 1:manageEmployees($message);break; default:break; } } </code></pre> <p>here is one of the forms that I am displaying on screen</p> <pre><code>&lt;tr&gt;&lt;th&gt;First Name&lt;/th&gt;&lt;th&gt;Last Name&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;th&gt;Password&lt;/th&gt;&lt;th&gt;Phone number&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input type="hidden" id="form_no" name="form_no" value="1"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input type="text" name="firstname[]" id="firstname"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="lastname[]" id="lastname"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email[]" id="email"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="password[]" id="password"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="phone_no[]" id="phone_no"&gt;&lt;/td&gt; &lt;td&gt;&lt;button type="submit" name="submit" id="submit"&gt;Add Employee&lt;/button&gt;&lt;/td&gt; &lt;td&gt;&lt;button type="button" name="delete" class="delete" value=21&gt;Delete Employee&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt; &lt;td&gt;&lt;p&gt;&lt;p&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I am trying to get access to other values in a form. When the button is clicked I can get the ID I am looking for as it is the value of the button. What I really want to do is get the value of the hidden field and find out in which for the delete button is pressed.</p> <p>I can not use find elementById as the delete buttons are not unique nor are the forms. I am trying to use <code>$(this).parents().parents('#form_no').val()</code>, however this returns undefined. </p> <p>I know that it must be possible to do but I am not getting any closer, many thanks in advance if any one can point me in the right direction. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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