为什么这个javascript函数没有调用?代码中的错误是什么? [英] why this javascript function is not calling?what is the error in the code?

查看:74
本文介绍了为什么这个javascript函数没有调用?代码中的错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Student Enquiry Form</title>
<script type="text/javaScript">
function f1()
{
var name=document.forms["form"]["name"].value;
if(name=="")
{
alert("Please enter your Name");
return false;
} 


var num=document.forms["form"]["phone"].value;
if(num=="")
{
alert("Please enter your Mobile number");
return false;
}

var em=document.forms["form"]["email"].value;
if(em=="")
{
alert("Please enter your E-mail Id");
return false;
}

var in=document.forms["form"]["interest"].value;
if(in=="")
{
alert("Please select your preferred course");
return false;
}

var stat=document.forms["form"]["state"].value;
if(stat=="")
{
alert("Please select your state");
return false;
}

var cit=document.forms["form"]["city"].value;
if(cit=="")
{
alert("Please select your city/centre");
return false;
}
return true;
}
</script>
</head>

<body>

<form id="form" name="form" method="post" action="#">
Carrer Guidance Form

<label>Name:</label>
<input type="text" name="name" id="name" />
<label>Mobile No:</label>
<input type="text" name="phone" id="phone" />
<label>Email ID:</label>
<input type="text" name="email" id="email" />
<label>Interested In:</label>
<select  name="interest" id="interest">
    <option selected="selected" value="">Select Course interested in</option>
	<option value="183">B.A. In Airline, Tourism & Hospitality Management</option>
	<option value="182">Diploma in Professional In-Flight & Ground Staff Services</option>
	<option value="181">Advanced Diploma in Aviation & Tourism</option>
	<option value="180">Diploma in Hospitality Management</option>
	<option value="64">Bachelor of Business Administration (BBA) - Aviation</option>
	<option value="179">Master of Business Administration (MBA) - Aviation</option>
	<option value="71">Pilot Training</option>
	<option value="72">Professional in Airport Management & Customer Care</option>
	<option value="66">Diploma in Airport Management & Customer Care</option>
	<option value="60">Aircraft Maintenance Engineering</option>
	<option value="61">Aptech certified professional in Cabin Crew Services</option>
	<option value="62">Aptech certified professional in Ground Staff Services</option>
	<option value="63">Aptech certified professional in Travel & Tourism</option>
	<option value="70">Personality Development Course</option>
	<option value="291">Event Management</option>

</select>
<label>State:</label>
<select name="state" id="state">
	<option selected="selected" value="">Select State</option>
</select>
<label>Preferred City/Centre:</label>
<select name="city" id="city" >
	<option value="">Select City/Centre</option>
</select>
By clicking on submit, I allow Aptech Aviation to call me and send program information on email/sms/phone.
<button  id="submit" name="submit"   önClick="return f1()">submit</button>

</form>

</body>
</html>

推荐答案

简单 - 你太懒了变量名。



获取正确的语法高亮编辑器,查看所有变量名称 - 瞧!其中一个是错误的颜色。解决它,它会触发。
Simple - you've been too lazy with your variable names.

Get a proper syntax-highlighting editor, look at all of your variable names and - voila! One of em is the wrong colour. Fix it, and it fires.


问题

Problem
var in=document.forms["form"]["interest"].value;

if(in=="")
{
    alert("Please select your preferred course");
    return false;
}



中的不能是变量名。



解决方案



因此,将其改为其他名称,如 interest



演示



现在,它正在工作完美。

查看演示 - [Demo]为什么这个javascript函数没有调用? [ ^ ]。


Here in cannot be a variable name.

Solution

So, change that to some other name like interest.

Demo

Now, it is working perfectly.
Check out the Demo - [Demo] why this javascript function is not calling?[^].


这篇关于为什么这个javascript函数没有调用?代码中的错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆