简体   繁体   English

我想当我点击模态上的单选按钮(objectart)时,它应该在另一个 div(objecttype)中更改模态上的其他 div 数据(获取数据库)

[英]i want when i click on radio button (objectart) on modal then it should change other div data (fetch database) on modal in another div(objecttype)

When I click on the button this modal pops up.当我单击按钮时,会弹出此模式。 Here is my Modal div code: If I click on objectart then objecttype option should be changed on Modal.这是我的 Modal div 代码:如果我单击 objectart,则应在 Modal 上更改 objecttype 选项。 Objecttype div is calling a function and fetch records according to objectart_id. Objecttype div 正在调用一个函数并根据 objectart_id 获取记录。 Through ajax, I am fetching the objectart_id.通过ajax,我正在获取objectart_id。 Please help me.请帮我。

Modal.php模态.php

    <div class="form-group row mb-3">
        <div class="modal" id="myModal">
            <div class="modal-content">
            <div class="modal-header">
                <span class="close" id="shut">&times;</span>
            </div>
            <div class="modal-body row">
                
                <div class="col-lg-3 p-2">
                    <div class="row">
                        <label><input type="radio" name="objektart_id" value="1">&ensp;Room</label>
                        <label><input type="radio" name="objektart_id" value="2" <?php echo ($objectart_id == 2) ? 'checked' : "" ?>>&ensp;Flat</label>
                        <label><input type="radio" name="objektart_id" value="3" <?php echo ($objectart_id == 3) ? 'checked' : "" ?>>&ensp;Haus</label>
                        <label><input type="radio" name="objektart_id" value="4" <?php echo ($objectart_id == 4) ? 'checked' : "" ?>>&ensp;Land</label>
                        <label><input type="radio" name="objektart_id" value="5" <?php echo ($objectart_id == 5) ? 'checked' : "" ?>>&ensp;Office</label>
                      </div>
                </div>
                <div class="col-lg-3 p-2">
                    <div class="row" id="objekttyp">
                        <label class="col-md-12 col-form-label">&ensp;Objecttype</label>
                        <?php echo getObjektartSubtyp($objectart_id); ?>
                    </div>
                </div>
               
                <div class="p-5" id="submit-detail">
                    <button type="submit" class="btn btn-success btn-lg mt-2 mt-sm-0">Search</button>
                </div>
            </div>
    
        </div>

</div>

myFunction.php

function getObjektartSubtyp($ids){函数 getObjektartSubtyp($ids){

    global $db;
    $sql = 'SELECT * FROM objekt_objektart_subtyp WHERE suche = "J" and objekt_objektart_id = ' . $ids;
    $result = $db->query($sql)->fetchAll();
    $html = '';
    foreach($result as $subtyp){
        $html.= '<label class="col-md-12 col-form-label search-objektart-subtyp" data-objektart="'.$subtyp['objekt_objektart_id'].'">
                    <input type="checkbox" name="objektart_subtyp_id[]" value="'.$subtyp['objekt_objektart_subtyp_id'].'"';
        
            // if(in_array($subtyp->objekt_objektart_subtyp_id, $ids)){ $html.= ' checked="checked"'; }
        
        $html.= '> '.$subtyp['name'].'</label>';
    }
    return $html;

}

Use ajax to fetch details from DB for a particular radio button, then update the objekttype division.使用 ajax 从 DB 获取特定单选按钮的详细信息,然后更新objekttype部门。

<script>
  var id;
  document.getElementsByName('objektart_id').forEach(item => {
  item.addEventListener('change', event => {
    if(item.checked == true) {
    id = item.getAttribute("object_id");
    //console.log(id); //for debugging
    //Now ajax call
    $.post("somePHP.php",{id: id, type: "get_subType"}, 
      function(data, status){
         if(status == "success"){
           $("#objekttype").html(data);
         }
      })
    };
  })
})
</script>

somePHP.php一些PHP.php

if(isset($_POSST['type'])){
    if($_POST['type'] == "get_subType"){
    global $db;
    $id = $_POST['id'];
    $sql = 'SELECT * FROM objekt_objektart_subtyp WHERE suche = "J" and objekt_objektart_id = ' . $ids;
    $result = $db->query($sql)->fetchAll();
    $html = '';
    foreach($result as $subtyp){
        $html.= '<label class="col-md-12 col-form-label search-objektart-subtyp" data-objektart="'.$subtyp['objekt_objektart_id'].'">
                    <input type="checkbox" name="objektart_subtyp_id[]" value="'.$subtyp['objekt_objektart_subtyp_id'].'"';
        
            // if(in_array($subtyp->objekt_objektart_subtyp_id, $ids)){ $html.= ' checked="checked"'; }
        
        $html.= '> '.$subtyp['name'].'</label>';
    }
    echo $html;
    }
}

If you prefer to have a separate function to get subtype you can add_action or call that function on type == 'get_subType' .如果您更喜欢使用单独的函数来获取子类型,您可以add_action或在type == 'get_subType'上调用该函数。

For any queries comment down.如有任何疑问,请评论。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击导航栏中的按钮或其他按钮时,它会将我重定向到一个名为 undefined 的页面,但我想要做的是打开一个引导模式 - When I click a button in navbar or other button it redirects me to a page called undefined but what I want to do is open a bootstrap modal 当我单击按钮时,我想随机旋转“ div” - I want to rotate a “div” randomly, when i click a button 我要始终在单击“提交”按钮时删除div容器吗? - I want to remove the div container always when click submit button? 当我使用 Javascript 和 JQuery 单击显示按钮时,我想在显示模式中显示我的 td 的图像数据,但找不到 src 的路径 - I want to display the image data of my td in the show modal when I click on the show button using Javascript and JQuery but path of the src not found 单击按钮时渲染模态-React - Render a modal when I click a button - React 当你点击一个按钮时,我想让一个 div 出现 - I want to make a div appear when you click a button 我想在单击添加按钮后关闭模式 - i want to close the modal after i click add button 单击按钮时模态不打开 - Modal not opening when I click on button 我已经制作了一个注册/登录页面,其中包含一个单选按钮以选择您是否要注册或登录,但 div 仅在您单击时更改 - I have made a register/sign in page with a radio button to choose if you want to register or log in, but div only changes when you click 我要在单击一个div时隐藏所有其他div - I want to hide all other div's when i click on one div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM