Hide dropdown when adding new row in JQuery

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Hide dropdown when adding new row in JQuery



In my Application, I can add a new row by clicking on the '+' sign.
When clicked on '+' sign new row got created but I want some particular field to be hidden when clicking on '+' sign and those hidden fields will be shown by satisfying some conditions. How can I achieve this feature when creating the new row?



Screenshot of the sample
Code for adding new row:


$("#addRow").click(function() {
openSearchdiv = true;
$("#searchTable").append('
<tr>
<td>
<select class="lovs" id="field" >
<option value="select"></option>
<option value="rowid_system">Source System Name</option>
<option value="rule_num">Rule No</option>
</select>
</td>
<td>
<select class="lovs" id="operator">
<option value="EQUAL">EQUAL</option>
<option value="NOT EQUAL">NOT EQUAL</option>
</select>
</td>
<td></td>
<td>
<select class="lovs" id="function">
<option value="AND">AND</option>
</select>
</td>
<td align="center"><img alt="" title="Delete" id="deleteRow" src="/MatchMergeAPI_POC/img/minus.png" style="height:15px;width:15px;"></td>
</tr>');
});



When the table first loaded I am hiding the value drop down. And it is visible by clicking on the field name. So I want this behavior to be the same when clicked on '+' sign. Presently I am just putting as blank when appending the table row.



Populating Dropdown values:


$("#searchTable").on('click','#field',function(){
//alert('hi');
//var showSpan = false;
var showHide = false;
var showRule = false;
var srcNameInd = false;
var src=null;

$("#searchTable tbody >tr").each(function()
{
$("td > *",this).each(function()
{
if (this.nodeName == "SELECT") {
if ($(this).attr("id") == "field") {

field = $(this).val();

if(field=="rowid_system" )
{
showHide=true;

console.log('rowid_system');

//populate value for source name
//$("#field").on('click',function(){
//alert('ajax call');
$.ajax({
url: contextPath+"/getSourceName/ORG",
datatype: "JSON",
type: "Get",
contentType : "application/json; charset=utf-8",
success: function(data)
{
srcName.populateSrcName(
data,
$('#srcName')

);
}

});




1 Answer
1



You could hide the select of the last row you've added to the table after the append line, like :


$("#searchTable tr:last select").hide();



Or you could add inline style while appending like :


$("#searchTable").append('<tr><td><select style="display:none" class="lovs" id="fi...');



You could also add a class that hides the field then remove it when you want to show it again :


.hide{
display: none;
}

$("#searchTable").append('<tr><td><select class="lovs hide" id="fi...');



And try to use event delegation on the click like :


$('body').on('click', '#addRow', function() {
//Your flow here
});





I can hide the value drop down by putting 'style="display:none" ' in each drop down. Now what I want is that the hidden drop down will be visible when choosing the field value.It is working when the "#searchTable" loaded but not working when clicking on '+' sign.
– Arindam Kotal
1 hour ago





The + sign you mean #addRow ?
– Zakaria Acharki
1 hour ago


+


#addRow





Yes '+' sign is for '#addRow'
– Arindam Kotal
1 hour ago





Try my update...
– Zakaria Acharki
1 hour ago





I did the change by adding 'style="display:none"'. But It only hides the drop down.I want to displaythose drop down when click on field options.
– Arindam Kotal
37 mins ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived