<script language="javascript" type="text/javascript">
function checkValue()
{
	if(document.addNum.categoryId1.value==0 && document.addNum.categoryId2.value==0 && document.addNum.categoryId3.value==0 && document.addNum.categoryId4.value==0 && document.addNum.categoryId5.value==0 && document.addNum.categoryId6.value==0 && document.addNum.categoryId7.value==0 && document.addNum.categoryId8.value==0 && document.addNum.categoryId9.value==0 && document.addNum.categoryId1.value==0)
	{
		alert('<?php echo $numberLBL["pleaseInsertOneNumber"];?>');
		document.addNum.categoryId1.focus();
		return false;
	}
	<?php for($i=1 ; $i <= 10; $i++) {?>
	if(document.addNum.categoryId<?php echo $i?>.value!=0)
	{
		if(document.addNum.number<?php echo $i?>.value == "")
		{
			alert('<?php echo $numberLBL["inserMobile"];?>');
			document.addNum.number<?php echo $i?>.focus();
			return false;
		}
		if(document.addNum.subCate<?php echo $i;?>.value ==0)
		{
			alert('<?php echo $numberLBL["pleaseInsetSubCat"];?>');
			document.addNum.number<?php echo $i?>.focus();
			return false;
		}
	}
	if(document.addNum.number<?php echo $i?>.value != "")
	{
		if(document.addNum.categoryId<?php echo $i?>.value ==0)
		{
			alert('<?php echo $numberLBL["selectCat"];?>');
			document.addNum.categoryId<?php echo $i?>.focus();
			return false;
		}
		if(document.addNum.subCate<?php echo $i;?>.value ==0)
		{
			alert('<?php echo $numberLBL["pleaseInsetSubCat"];?>');
			document.addNum.subCate<?php echo $i?>.focus();
			return false;
		}
	}
<?php }?>
}
</script>
<form name="addNum" method="POST" action="numberModalAddDirectName2.php" onsubmit="return checkValue();" style="margin:0px">
   <div class="modal fade bd-example-modal-lg" style="z-index:10000;padding-<?php echo $align;?>:0px" id="addDirectNameNumbersModal" tabindex="-1" role="dialog" aria-labelledby="addDirectNameNumbersModalTitle" aria-hidden="true">
      <div class="modal-dialog modal-lg" role="document">
         <div class="modal-content text-right">
            <div class="modal-header modal-header-primary">
               <h5 class="modal-title" id="addDirectNameNumbersModalTitle"><?php echo $numberLBL["addDirectNameNumbers"];?></h5>
               <button type="button" class="close slidedown" data-dismiss="modal" aria-label="Close">
               <span aria-hidden="true">&times;</span>
               </button>
            </div>
            <div class="modal-body" style="text-align: <?php echo $align;?>;">
                <div class="table-responsive">
                   <table class="table table-borderless">
                      <thead>
                         <tr>
                            <th scope="col"><?php echo $numberLBL["category"];?></th>
                            <th scope="col" nowrap><?php echo $numberLBL["subCategory"];?></th>
                            <th scope="col"><?php echo $numberLBL["name"];?></th>
                            <th scope="col"><?php echo $numberLBL["mobile"];?></th>
                            <th scope="col"><?php echo $numberLBL["city"];?></th>
                         </tr>
                      </thead>
                      <tbody>
                      <?php
						for($i=1 ; $i <= 10; $i++) {
                        ?>
                         <tr>
                            <td>
                            <select name="categoryId<?php echo $i;?>" id="categoryId<?php echo $i;?>"  class="form-control" style="padding: 0px;width:150px">
                                <option value='0'><?php echo $numberLBL["select"];?></option>
                                <?php
                                $query  = "SELECT id, name FROM $userCategory WHERE userId='".$_SESSION["userId"]."'";
                                $result = mysqli_query($conn, $query);
                                $num = mysqli_num_rows($result);
                                while($row= mysqli_fetch_array($result))
                                {
                                    ?>
                                <option value="<?php echo $row['id'];?>"><?php echo $row['name'];?></option>
                                    <?php
                                }
                                ?>
                            </select>
                            </td>
                            <td>
                            <select id="subCate<?php echo $i;?>" name="subCate<?php echo $i;?>"  class="form-control" style="padding: 0px;width:150px">
                                <option value='0'><?php echo $numberLBL["select"];?></option>
                            </select>
                           </td>
                           <td>
                           <input type="text" class="form-control" name="name<?php echo $i;?>">
                           </td>
                           <td>
                           <input type="text" class="form-control" name="number<?php echo $i;?>">
                           </td>
                           <td>
                           <input type="text" class="form-control" name="city<?php echo $i;?>">
                           </td>
                         </tr>
                         <?php
                           }
                        ?>
                      </tbody>
                   </table>
               </div>
            </div>
            
            <div class="modal-footer">
               <button type="button" class="btn bg-danger btn-flat text-white m-1" data-dismiss="modal"><?php echo $button["close"];?></button>
               <input type="submit" value='<?php echo $button["add"];?>' id="submit1" class="btn bg-primary btn-flat text-white m-1">
            </div>
         </div>
      </div>
   </div>
        <input type="hidden" value="1" name="addDirect" />
</form>
<script language="javascript" type="text/javascript">
	$(document).ready(function(){
	<?php
	for($i=1 ; $i <= 10; $i++) {
	 ?>
		$("#categoryId<?php echo $i;?>").change(function (){
			$.post("fetchSubCategory.php",{ id:$("#categoryId<?php echo $i;?>").val(),rand:Math.random() } ,function(res){
			$("#subCate<?php echo $i;?>").html(res);
			});
		});
	});
	
	$.post("fetchSubCategory.php",{ id:$("#categoryId<?php echo $i;?>").val(),rand:Math.random() } ,function(res){
	$("#subCate<?php echo $i;?>").html(res);
 <?php
			}
			?>
		});
</script>