Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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中打开的输入验证文本框_Javascript_Php_Jquery_Html_Mysql - Fatal编程技术网

如何根据javascript中打开的输入验证文本框

如何根据javascript中打开的输入验证文本框,javascript,php,jquery,html,mysql,Javascript,Php,Jquery,Html,Mysql,我正在构建我的网站,在那里我为用户提供了在那里构建的选项自定义URL。我正在从数据库中验证的自定义url是mysql。如果自定义url已经存在,则必须在其中更改自定义url。如果用户不想要自定义url,则不会选择该单选按钮 我的问题是,我的代码正在验证文本框,即使他们没有选择customurl选项,因此表单没有提交 这是我的密码: <html> <body> <form action="insertdata.php" id="contact

我正在构建我的网站,在那里我为用户提供了在那里构建的选项
自定义URL
。我正在从数据库中验证的自定义url是
mysql
。如果自定义url已经存在,则必须在其中更改自定义url。如果用户不想要自定义url,则不会选择该单选按钮

我的问题是,我的代码正在验证文本框,即使他们没有选择customurl选项,因此表单没有提交

这是我的密码:

    <html>
    <body>
     <form action="insertdata.php" id="contact-form1" class="mar_l10" method="post">
     <p><input type="radio" name="cust1" value="2" onclick="hide();" class="display_inline">Dont want</p>
     <p><input type="radio" name="cust2" value="3" onclick="show();" class="display_inline">Custom URL need</p>
     <p id="showlabel" style="display: none;" onblur="test(this);">Custom URL</p>
    <input type="text"  name="url" id="url" style="display: none;" onblur="test(this);" class="display_inline" maxlength="20"/>
<div id="user_status"></div>
     <input type="submit" id="continue_details" value="Continue" title="Continue" class="submit_btn" >   
     </form>



     <script type="text/javascript">
            function show()
            {
            document.getElementById('url').style.display = 'block'; 
            document.getElementById('hostname').style.display = 'block';
            document.getElementById('checkurl').style.display = 'block'; 
            document.getElementById('showlabel').style.display = 'block';
            }
             function hide() 
             { 
             document.getElementById('url').style.display = 'none'; 
                 document.getElementById('hostname').style.display = 'none';
             document.getElementById('checkurl').style.display = 'none'; 
             document.getElementById('showlabel').style.display = 'none';
             }



    var flag = true;
    $('#contact-form1').submit(function(e){
    e.preventDefault();

    if($('#user_status').val() == " "){
     document.getElementById('contact-form1').submit();
        //return true;
    }
    else
    {
    test();
    $('.user_status').show();

    }




    })



    function test()
    {   
        var username = document.getElementById('url').value;
        var url = "check_url.php?username="+username;

       if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function()
        {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {

                var result = xmlhttp.responseText;
                if(xmlhttp.responseText =='Custom URL is available')
                {
                    document.getElementById('user_status').innerHTML =result ;

                    document.getElementById('contact-form1').submit();

                }
                else
                {
                   document.getElementById('user_status').innerHTML =result ;
                }

            }
        }


        xmlhttp.open("GET",url,true);

        xmlhttp.send();

    }
     </script>



     </body>
     </html>

不要

自定义URL需要

自定义URL

函数show() { document.getElementById('url').style.display='block'; document.getElementById('hostname').style.display='block'; document.getElementById('checkurl').style.display='block'; document.getElementById('showlabel').style.display='block'; } 函数hide() { document.getElementById('url').style.display='none'; document.getElementById('hostname').style.display='none'; document.getElementById('checkurl').style.display='none'; document.getElementById('showlabel').style.display='none'; } var标志=真; $(#contact-form1')。提交(功能(e){ e、 预防默认值(); if($('#用户_状态').val()=“”){ document.getElementById('contact-form1').submit(); //返回true; } 其他的 { test(); $('.user_status').show(); } }) 功能测试() { var username=document.getElementById('url')。值; var url=“check_url.php?username=“+username; if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { var result=xmlhttp.responseText; 如果(xmlhttp.responseText=='自定义URL可用') { document.getElementById('user_status')。innerHTML=result; document.getElementById('contact-form1').submit(); } 其他的 { document.getElementById('user_status')。innerHTML=result; } } } open(“GET”,url,true); xmlhttp.send(); }
对于自定义url选项,请单击数据库验证是否正常工作以及表单是否提交。但是,如果我选择不需要自定义url选项,表单也会验证url文本框

谁能帮我一下吗


谢谢。

您需要进行测试,以查看在进行测试时是否检查了cust2

if($('input[name=cust2]').is(':checked'))
{
  test();
}

您应该让单选按钮具有相同的名称,以使它们相互排斥。不过,这是查询的辅助功能。

在调用测试函数之前,必须选中单选按钮,如下所示:

else if ($('form input[type=radio]:checked').val() == 3) 

请显示您的验证谢谢您的回复。您想看到什么验证..php代码?您告诉我,
我的代码正在验证该文本框,即使他们没有选择customurl选项,我想看到任何情况下的验证。我更改的代码是var flag=true$('#contact-form1').submit(函数(e){if($('#user_status').val()==“”){document.getElementById('contact-form1').submit()//返回true;}否则($('form input[type=radio]:checked').val()==3){test();$('user#status').show()})如果不是萨姆比特,这是萨姆比特,请帮助我这是什么期望?它应该什么时候提交?我需要在点击选项1时直接提交表单,在点击选项2时,它应该仅在customurl可用的情况下提交。对于上述代码,它还将在不应提交的情况下提交表单。请在这方面帮助我。我想您丢失了上面的几行代码,我没有看到任何提交表单的内容——如
e.preventDefault()应阻止表单提交。在其他错误可能存在的地方有一些可疑的空行(如果您没有在StackOverflow的右侧或此处留出空格)。