Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 成功 //perl_数据应该包含perl脚本返回的字符串 成功:函数(perl_数据){ $('div#contactCatcher').html(perl#u数据); } }); } }); }); 您可以显示您的html代码吗?当然可以。我用H_Javascript_Jquery_Ajax_Events - Fatal编程技术网

Javascript 成功 //perl_数据应该包含perl脚本返回的字符串 成功:函数(perl_数据){ $('div#contactCatcher').html(perl#u数据); } }); } }); }); 您可以显示您的html代码吗?当然可以。我用H

Javascript 成功 //perl_数据应该包含perl脚本返回的字符串 成功:函数(perl_数据){ $('div#contactCatcher').html(perl#u数据); } }); } }); }); 您可以显示您的html代码吗?当然可以。我用H,javascript,jquery,ajax,events,Javascript,Jquery,Ajax,Events,成功 //perl_数据应该包含perl脚本返回的字符串 成功:函数(perl_数据){ $('div#contactCatcher').html(perl#u数据); } }); } }); }); 您可以显示您的html代码吗?当然可以。我用HTML更新了我的帖子。但是我不得不说,问题来自JS内部的HTML部分(在if(id_client==“free”)条件中),而不是来自主HTML。顺便说一下,这个JS的其余部分工作得很好,我只是输入字段变为空…你说得对。我将表单标记移到了div

成功 //perl_数据应该包含perl脚本返回的字符串 成功:函数(perl_数据){ $('div#contactCatcher').html(perl#u数据); } }); } }); });
您可以显示您的html代码吗?当然可以。我用HTML更新了我的帖子。但是我不得不说,问题来自JS内部的HTML部分(在
if(id_client==“free”)
条件中),而不是来自主HTML。顺便说一下,这个JS的其余部分工作得很好,我只是输入字段变为空…你说得对。我将表单标记移到了
div#contactCatcher
之前,但它没有解决问题。我怀疑
change
事件强制输入标记的值为空…@Satch Yes。我已经编辑了我的答案。希望对你有帮助!谢谢,但不幸的是,您的代码只适用于
change()
。如果html页面准备就绪时已选择了一个
id\u client\u facture
,则不会执行
ready()
函数。但我最终找到了一个解决方案(见下文)。虽然不太漂亮,但很管用。无论如何,谢谢你的帮助!太酷了!!
$(document).on('change ready', function(){
$(".select_client").ready(function() {

var e = document.getElementById("InputClient");
var id_client = e.options[e.selectedIndex].value;

if (id_client == "free") // values are not empty
 {
 $('div#contactCatcher').html("<div class=\"form-group\"><label for=\"ContactNom\">Nom</label><input type=\"text\" class=\"form-control\" name=\"contact_nom\" id=\"ContactNom\"></div><div class=\"form-group\"><label for=\"ContactAdresse\">Adresse</label><input type=\"text\" class=\"form-control\" name=\"contact_adresse\" id=\"ContactAdresse\"></div><div class=\"form-group col-xs-6\"><label for=\"ContactCodePostal\">Code postal</label><input type=\"text\" class=\"form-control\" name=\"contact_code_postal\" id=\"ContactCodePostal\"></div><div class=\"form-group col-xs-6\"><label for=\"ContactVille\">Ville</label><input type=\"text\" class=\"form-control\" name=\"contact_ville\" id=\"ContactVille\"></div><div class=\"form-group\"><label for=\"ContactPays\">Pays</label><input type=\"text\" class=\"form-control\" name=\"contact_pays\" id=\"ContactPays\"></div>");
}
else if (id_client) 
{
$.ajax({
    type: "POST",
    url: "http://satch/suivi-hbl/misc/scripts/get_client.pl", // URL of the Perl script

    // send id_client and name as parameters to the Perl script
    data: "id_client_facture=" + id_client,

    // script call was *not* successful
    error: function() { 
        alert("script call was not successful");
    }, 

    // script call was successful 
    // perl_data should contain the string returned by the Perl script 
    success: function(perl_data){
        $('div#contactCatcher').html(perl_data);
    }
});   
}

else {
$('div#contactCatcher').html("Veuillez s\&eacute\;lectionner un client.");
//  $('div#contactCatcher').addClass("error");
}

$('div#contactCatcher').fadeIn();
return false;
}).change();
});
    <!-- ----------------- Show client ---------------- -->
    <p><div id="contactCatcher">Veuillez s&eacute;lectionner un client.
    </div></p>


    <!-- ----------------- Selection client ---------------- -->
    <form id="loginForm" name="loginForm" method="post" action="script.pl">

    <div class="form-inline">
        <label for="InputClient">Client &nbsp; </label>
            <select class="form-control select_client" name="id_client_facture" id="InputClient">
            <option value="">Select please</option>
            <option value="1">John Woolof</option>
            <option value="2">Marc Dabrani</option>
            ......
            <option value="free">Other</option>
            </select>
    </div>

    ........
<!-- ----------------- Show client ---------------- -->
<div id="contactCatcher">
    <p>Veuillez s&eacute;lectionner un client.</p>
</div>


<!-- ----------------- Selection client ---------------- -->
<form id="loginForm" name="loginForm" method="post" action="script.pl">

<div class="form-inline">
    <label for="InputClient">Client &nbsp; </label>
        <select class="form-control select_client" name="id_client_facture" id="InputClient">
        <option value="">Select please</option>
        <option value="1">John Woolof</option>
        <option value="2">Marc Dabrani</option>
        ......
        <option value="free">Other</option>
        </select>
</div>
$(document).ready(function(){
    $("#InputClient").change(function() {
    var id_client = $(this).val();

    if ($(this).val() == "free") // values are not empty
    {
        $('div#contactCatcher').html("<div class=\"form-group\"><label for=\"ContactNom\">Nom</label><input type=\"text\" class=\"form-control\" name=\"contact_nom\" id=\"ContactNom\"></div><div class=\"form-group\"><label for=\"ContactAdresse\">Adresse</label><input type=\"text\" class=\"form-control\" name=\"contact_adresse\" id=\"ContactAdresse\"></div><div class=\"form-group col-xs-6\"><label for=\"ContactCodePostal\">Code postal</label><input type=\"text\" class=\"form-control\" name=\"contact_code_postal\" id=\"ContactCodePostal\"></div><div class=\"form-group col-xs-6\"><label for=\"ContactVille\">Ville</label><input type=\"text\" class=\"form-control\" name=\"contact_ville\" id=\"ContactVille\"></div><div class=\"form-group\"><label for=\"ContactPays\">Pays</label><input type=\"text\" class=\"form-control\" name=\"contact_pays\" id=\"ContactPays\"></div>");
    }
    else if ($(this).val() == "") 
    {
        $('div#contactCatcher').html("Veuillez s\&eacute\;lectionner un client."); 
    }else {

        $.ajax({
            type: "POST",
            url: "http://satch/suivi-hbl/misc/scripts/get_client.pl", // URL of the Perl script

            // send id_client and name as parameters to the Perl script
            data: "id_client_facture=" + id_client,

            // script call was *not* successful
            error: function() { 
                alert("script call was not successful");
            }, 

            // script call was successful 
            // perl_data should contain the string returned by the Perl script 
            success: function(perl_data){
                $('div#contactCatcher').html(perl_data);
            }
        }); 
    }

    $('div#contactCatcher').fadeIn();
    return false;
    });
});
$(document).ready(function(){
$(".select_client").change(function() {

var e = document.getElementById("InputClient");
var id_client = e.options[e.selectedIndex].value;

if (id_client != "free")
 {


if (id_client) 
{
$.ajax({
    type: "POST",
    url: "http://satch/suivi-hbl/misc/scripts/get_client.pl", // URL of the Perl script

    // send id_client and name as parameters to the Perl script
    data: "id_client_facture=" + id_client,

    // script call was *not* successful
    error: function() { 
        alert("script call was not successful");
    }, 

    // script call was successful 
    // perl_data should contain the string returned by the Perl script 
    success: function(perl_data){
        $('div#contactCatcher').html(perl_data);
    }
});   
}

else {
$('div#contactCatcher').html("Veuillez s\&eacute\;lectionner un client.");
//  $('div#contactCatcher').addClass("error");
}


$('div#contactCatcher').fadeIn();
return false;

}
else
{
$('div#contactCatcher').html("<div class=\"form-group\"><label for=\"ContactNom\">Nom</label><input type=\"text\" class=\"form-control\" name=\"contact_nom\" id=\"ContactNom\"></div><div class=\"form-group\"><label for=\"ContactAdresse\">Adresse</label><input type=\"text\" class=\"form-control\" name=\"contact_adresse\" id=\"ContactAdresse\"></div><div class=\"row\"><div class=\"form-group col-xs-6\"><label for=\"ContactCodePostal\">Code postal</label><input type=\"text\" class=\"form-control\" name=\"contact_code_postal\" id=\"ContactCodePostal\"></div><div class=\"form-group col-xs-6\"><label for=\"ContactVille\">Ville</label><input type=\"text\" class=\"form-control\" name=\"contact_ville\" id=\"ContactVille\"></div></div><div class=\"form-group\"><label for=\"ContactPays\">Pays</label><input type=\"text\" class=\"form-control\" name=\"contact_pays\" id=\"ContactPays\"></div>");
}

});


}).change();








$(document).ready(function(){
$(".select_client").ready(function() {

var e = document.getElementById("InputClient");
var id_client = e.options[e.selectedIndex].value;

if (id_client) 
{
$.ajax({
    type: "POST",
    url: "http://satch/suivi-hbl/misc/scripts/get_client.pl", // URL of the Perl script

    // send id_client and name as parameters to the Perl script
    data: "id_client_facture=" + id_client,

    // script call was *not* successful
    error: function() { 
        alert("script call was not successful");
    }, 

    // script call was successful 
    // perl_data should contain the string returned by the Perl script 
    success: function(perl_data){
        $('div#contactCatcher').html(perl_data);
    }
   });   
}



});


});