How to transfer value from a child modal child to a parent?

I tried to pass any value from my modal window mod to the parent window, but it does not work. modalnot hideor send the value to the parent window when I click Save.

application.php

<body>
<h3 class="h3 black">Application</h3>
<form class="form-horizontal" method="post" action="admin-controller.php" name="f1">
<input type="text" name="p_name" id="n1" > 
<?php 
    include 'includes/calendar.php';
    $calendar = new Calendar();
    echo $calendar->show();
?>   
</form>
</body>   
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0  /jquery.validate.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript"> 
function post_value(){
    window.opener.document.f1.p_name = document.myform.skill_id_t.value;
    $('#modal_1').modal('hide');
}
</script>

calendar.php

<?php
class Calendar {    
public function show() {
    //some code
    $html .=$this->_showDay($someValues);
    //some code      
}

private function _showDay($cellNumber){      
   // Build up the html.
    $html = '<td id="' . $this->currentDate . '" class="td-top-text ' . $classNameOne .  $classNameTwo . '">';
    //Radio button that open the Modal window
    $html .= '<input type="radio" data-toggle="modal" data-target="#modal_1" name="schedule_id" value="'. $shedule_id.'">'; 
    //singleModal
    $html .=$this->_singleModal();
    $html .= '</td>';       
    return $html; 
 }

 //child window
 public function _singleModal(){
    //Single Modal
    $html = '<form name="myform" method="post" action="">';
    $html .= '<div class="modal fade" id="modal_1" role="dialog">';//Modal open
        $html .= '<div class="modal-dialog">';//Modal Dialog open
            $html .= '<div class="modal-content">';//Modal-Content Open
                $html .= '<div class="modal-header">';//Modal-Header open
                    $html .= '<button type="button" class="close" data-dismiss="modal">&times;</button>';//bbutton
                    $html .= '<h4 class="modal-title bold cyan">Sign Up (Single)</h4>';//Title H4
                $html .= ' </div>';//Modal-header Close      
                $html .= '<div class="modal-body">';//Modal-body open

                //Type something to pass to parent window 
                $html .= '<input name="skill_id_t" type="text">';

                $html .= '</div>';//Modal-body close

                $html .= '<div class="modal-footer">';//Footer open
                    $html .= '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';//button
                    $html .= '<input onclick="post_value();" id="save" type="button" name="save-details" value="Save">';//input
                $html .= '</div>';//Footer Close
            $html .= '</div>';//Modal-content close
        $html .= '</div>';//Modal Dialog Close
    $html .= '</div>';//Modal close
    $html .= '</form>';
    return $html;  
   }
  }

I read other messages and, according to them, the problem may be javascriptbecause I can not use data-target="#modal_1"with javascript, so I tried to delete targetand just add onclicka function call to my <input name="schedule_id">execute $(#modal_1).modal('show');, but still does $(#modal_1).modal('hide');not work.

I also had a tag phpbecause, according to other posts, I need to include javascriptin mine php( calendar.php), not mineapplication.php

Edit , Save

TypeError: openener null

, window.opener...,

:

js :

$(function() {
$('#btnLaunch_1').click(function() {
  $('#modal_1').modal('show');
});

$('#btnSave_1').click(function() {
  opener.document.f1.p_name = document.myform.skill_id_t.value;
  $('#modal_1').modal('hide');
});

 $('#cancel_1').click(function() { 
     $('#modal_1').modal('hide');
 });
});

, data-target, , data-dismiss. , opener.document.f1.p_name = document.myform.skill_id_t.value; - , . ...opener is null

, =/II .

+4
2

, , , , bootstrap - jQuery :

$(function() {

//open modal
$('#btnLaunch_1').click(function() {
    $('#modal_1').modal('show');//no need data-target just <input id="">
});

$('#btnSave_1').click(function() {

    //Get the value from the child into a variable
    value = $('[name="skill_id_1"]').val();

    //Set the value to the parent window
    $('[name="p_name"]').val(value);

    //make the modal dismiss (no need data-target)
    $('#modal_1').modal('hide');
});

   //if user click cancel instead of use data-dismiss, just hide it
$('#cancel_1').click(function() {
   $('#modal_1').modal('hide');
});

});

, ,

0

;

window.opener.document.f1.p_name to

window.opener.document.myform.p_name

<form name="myform" method="post" action="">

0

Source: https://habr.com/ru/post/1627464/


All Articles