Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Chained SELECT Tag JavaScript and jQuery
    primarykey
    data
    text
    <p>Good Day! :) </p> <p>I created a chained select using php and jQuery like on this page <a href="http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/" rel="nofollow">http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/</a> and I created a javascript to add and delete select tags I get it somewhere on the internet but what happening is when I choose a category on the first line everything on the subcategory will be enabled and also on the product description. Just like this <a href="http://i.stack.imgur.com/H9nfb.jpg" rel="nofollow">http://i.stack.imgur.com/H9nfb.jpg</a> </p> <p><strong>this is my code:</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("select#type").attr("disabled", "disabled"); $("select#category").change(function() { $("select#type").attr("disabled", "disabled"); $("select#type").html("&lt;option&gt;wait...&lt;/option&gt;"); var id = $("select#category option:selected").attr('value'); $.post("select_type.php", { id: id }, function(data) { $("select#type").removeAttr("disabled"); $("select#type").html(data); }); }); $("select#desc").attr("disabled", "disabled"); $("select#type").change(function() { $("select#desc").attr("disabled", "disabled"); $("select#desc").html("&lt;option&gt;wait...&lt;/option&gt;"); var id = $("select#type option:selected").attr('value'); $.post("select_desc.php", { id: id }, function(data) { $("select#desc").removeAttr("disabled"); $("select#desc").html(data); }); }); $("form#select_form").submit(function() { var cat = $("select#category option:selected").attr('value'); var type = $("select#type option:selected").attr('value'); var descr = $("select#desc option:selected").attr('value'); if (cat &gt; 0 &amp;&amp; type &gt; 0 &amp;&amp; descr &gt; 0) { var result = $("select#desc option:selected").html(); $("#result").html('your choice: ' + result); } else { $("#result").html("you must choose two options!"); } return false; }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for (var i = 0; i &lt; colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[1].cells[i].innerHTML; //alert(newcell.childNodes); switch (newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for (var i = 0; i &lt; rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if (null != chkbox &amp;&amp; true == chkbox.checked) { if (rowCount &lt;= 2) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } } catch (e) { alert(e); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php include "select.class.php"; ?&gt; &lt;form id="select_form"&gt; &lt;input type="button" value="Add" onclick="addRow('tableID')" /&gt; &lt;input type="button" value="Delete" onclick="deleteRow('tableID')" /&gt; &lt;table id="tableID"&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;Category&lt;/td&gt; &lt;td&gt;SubCategory&lt;/td&gt; &lt;td&gt;Product Description&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name="chkbox[]" /&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="category" name="category[]"&gt; &lt;?php echo $opt-&gt;ShowCategory(); ?&gt;&lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="type" name="type[]"&gt; &lt;option value="0"&gt;choose...&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="desc" name="desc[]"&gt; &lt;option value="0"&gt;choose...&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" value="confirm" /&gt; &lt;/form&gt; &lt;div id="result" name="result[]"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Hope anyone could help me. :)</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