Javascript 我的提交按钮不起作用

Javascript 我的提交按钮不起作用,javascript,html,form-submit,submit-button,Javascript,Html,Form Submit,Submit Button,我试图用java脚本提交我的表单。但是它没有按它应该的那样工作,它没有从脚本中获得值。它只适用于html正文中的警报编码,但它没有读取函数check(),我的表单有问题吗 <form name="myForm" method="post" onsubmit="return check()"> <table width="100%"> <tr>

我试图用java脚本提交我的表单。但是它没有按它应该的那样工作,它没有从脚本中获得值。它只适用于html正文中的警报编码,但它没有读取函数check(),我的表单有问题吗

<form name="myForm" method="post" onsubmit="return check()">
                        <table width="100%">
                        <tr>
                            <div id="space">
                                YOUR DETAILS 
                            </div><!-- space -->
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>First Name</td>
                            <td width="720">
                            <input type="text" name="fname">
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>Last Name</td>
                            <td width="720">
                            <input type="text" name="lname">
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>Email</td>
                            <td width="720">
                            <input type="email" name="email">
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>Telephone</td>
                            <td width="720">
                            <input type="tel" name="telephone">
                            </td>
                        </tr>
                        <tr>
                            <td width="186">Fax</td>
                            <td width="720">
                            <input type="tel" name="fax">
                            </td>
                        </tr>
                        <tr>
                            <td width="186">Company</td>
                            <td width="720">
                            <input type="text" name="company">
                            </td>
                        </tr>
                        <tr>
                            <td width="186">Company ID</td>
                            <td width="720">
                            <input type="text" name="cid">
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>Address 1</td>
                            <td width="720">
                            <input type="text" name="add1">
                            </td>
                        </tr>
                        <tr>
                            <td width="186">Address 2</td>
                            <td width="720">
                            <input type="text" name="add2">
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>City</td>
                            <td width="720">
                            <input type="text" name="city" >
                            </td>
                        </tr>
                        <tr>
                            <td width="186">Poscode</td>
                            <td width="720">
                            <input type="text" name="poscode" >
                            </td>
                        </tr>
                        <tr>
                            <td width="186"><span style="color:red;">*</span>Country</td>
                            <td width="720">
                                <select name="country">
                                    <option value="malaysia">Malaysia</option>
                                    <option value="australia">Australia</option>
                                    <option value="japan">Japan</option>
                                    <option value="newzealand">New Zealand</option>
                                </select>
                            </td>
                        </tr>
                        </table>

                        <br><br>

                        <input type="button" onclick="check()" name="submit" value="Submit" class="sbutton" />
                        <button name="subcancel" class="sbutton" value="Cancel" >CANCEL</button>
                        </form>

}检查以下工作代码:

函数检查(){
警报(“hi”);
var isi1=document.forms[“myForm”][“fname”].value;
var isi2=document.forms[“myForm”][“lname”].value;
var isi3=document.forms[“myForm”][“email”].value;
var isi4=document.forms[“myForm”][“电话”]。值;
var isi5=document.forms[“myForm”][“add1”]值;
var isi6=document.forms[“myForm”][“city”].value;
var isi7=document.forms[“myForm”][“country”]。值;
如果(isi1==“”){
警告(“请用“*”符号填写您的所有详细信息!”);
返回false;
}
否则如果(isi2==“”){
提醒(“请填写您的详细信息!”);
返回false;
}
否则如果(isi3==“”){
提醒(“请填写您的详细信息!”);
返回false;
}
else if(isi4==“”){
提醒(“请填写您的详细信息!”);
返回false;
}
else if(isi5==“”){
提醒(“请填写您的详细信息!”);
返回false;
}
否则如果(isi6==“”){
提醒(“请填写您的详细信息!”);
返回false;
}
否则{
警报(“嗨”+isi1+“+isi2+”!!您已成功注册到我们的书店!!”;
返回true;
}
}

你的细节
*名字
*姓
*电子邮件
*电话
传真
公司
公司ID
*地址1
地址2
*城市
邮政编码
*国家
马来西亚
澳大利亚
日本
新西兰


取消
Javascript!=JavaWell您不需要取消标记中的clickRemove
onsubmit=“return check()”
。将check()事件处理程序添加到按键。使用AJAX手动提交,或者添加表单POST目标和
form.submit()
您可能无法从check()处理程序返回以阻止提交。因此,请使用
if(isValid)form.submit()
ps:您可以循环检查所有这些值是否为空字符串。谢谢,它在我的浏览器中突然起作用。您只需在javascript上添加警报,对吗?问题出现在这一行var isi4=document.forms[“myForm”[“tel”].value;错误的名称“电话”
function check(){
alert('hi');
var isi1=document.forms["myForm"]["fname"].value;
var isi2=document.forms["myForm"]["lname"].value;
var isi3=document.forms["myForm"]["email"].value;
var isi4=document.forms["myForm"]["tel"].value;
var isi5=document.forms["myForm"]["add1"].value;
var isi6=document.forms["myForm"]["city"].value;
var isi7=document.forms["myForm"]["country"].value;

if (isi1 == "") {
     alert("Please complete all your detail with '*' symbol!");
     return false;
}
else if(isi2 ==""){
     alert("Please complete your detail!");
     return false;
}
else if(isi3 ==""){
     alert("Please complete your detail!");
     return false;
}
else if(isi4 ==""){
     alert("Please complete your detail!");
     return false;
}
else if(isi5 ==""){
     alert("Please complete your detail!");
     return false;
}
else if(isi6 ==""){
     alert("Please complete your detail!");
     return false;
}
else{
    alert("Hi "+isi1+" "+isi2+"!! You are succesfully registered to our bookstore!!");
    return true;
}