English 中文(简体)
A. 简讯
原标题:Need JavaScript validation and submission

我做了一定数额的确认,但不能阻止提交。 请帮助我验证其他遗留领域。 这是我的法典:

<form action="" method="post" id="contacts-form" onsubmit="return >
<fieldset>
<div class="field">
<input type="text" value="Name:" id="name" onfocus="if(this.value== Name: ){this.value=  }" onblur="if(this.value==  ){this.value= Name: }" />`enter code here`
</div>
<div class="field">
<input type="text" value="E-mail:" id="email" onfocus="if(this.value== E-mail: ){this.value=  }" onblur="if(this.value==  ){this.value= E-mail: }" />
</div>
<div>
<textarea cols="1" rows="1" id="message" onfocus="if(this.value== Message: ){this.value=  }" onblur="if(this.value==  ){this.value= Message: }">Message:</textarea>
</div>
<div class="link"><a href="#" onclick="document.getElementById( contacts-form ).reset()">Clear</a> &nbsp; &nbsp; <a href="#" onclick="document.getElementById( contacts-form ).submit(validateForm();)">Send</a></div> 

www.un.org/Depts/DGACM/index_spanish.htm The Js Code I used is this:

function validateForm()
{
var x=document.forms["contacts-form"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
问题回答
 change onsubmit="return >
         onsubmit="return validateForm();"

并且还关闭了这些及带、形形形和斜体;以及 /fieldset >

希望:

onsubmit=“return >改为onSubmit=“return validateForm();>

以及

Replace

<div class="link"><a href="#" onclick="document.getElementById( contacts-form ).reset()">Clear</a>    &nbsp; &nbsp; <a href="#" onclick="document.getElementById( contacts-form ).submit()">Send</a></div>

You now execute the validateForm on submit 以及 if it fails the onSubmit gets the false from your function 以及 will not submit/reload the site.

我不敢肯定,但如果有必要的话,你也可以在你的职能中设置一个<代码>。

类似情况(可能有一些错误,因此,我是在没有检查的情况下撰写):

function validateForm(){
var x=document.forms.contacts-form.email.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
    alert("Not a valid e-mail address");
    return false;
}
else {
    document.forms.contacts-form.submit();
}
}

和 html:

<form action=   name= contacts-form  method= post >
<fieldset>
<div class="field">
<input type="text" value="Name:" id="name" onfocus="if(this.value== Name: )            {this.value=  }" onblur="if(this.value==  ){this.value= Name: }" />`enter code here`
</div>
<div class="field">
<input type="text" value="E-mail:" id="email" onfocus="if(this.value== E-mail: )        {this.value=  }" onblur="if(this.value==  ){this.value= E-mail: }" />
</div>
<div>
<textarea cols="1" rows="1" id="message" onfocus="if(this.value== Message: )        {this.value=  }" onblur="if(this.value==  ){this.value= Message: }">Message:</textarea>
</div>
<div class="link"><a href="#" onclick="document.getElementById( contacts-vform ).reset()">Clear</a> &nbsp; &nbsp; <button value="Send" onclick="validateForm()"></div>
</fieldset>
</form>

努力这样做:

www.un.org/spanish/ecosoc

function validateForm()
{
var isValid =true;
var x=document.forms["contacts-form"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
isValid= false;
}
retrun isValid;
}





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签