Jquery表单从字段值获取
我在我的网站上使用 Jquery 表单。发件人非常简单,包含常用字段(姓名、电子邮件、出生日期等)。用户按下注册按钮后,表单将使用 Jquery 的“ajaxForm”参数提交到 php 文件。之后,表单滑出,谷歌地图滑入,要求客户通过拖动地图上的标记来选择他当前的位置。
将标记放置在所需位置后,客户可以单击“提交”按钮,两个值将传递到另一个 php 文件:纬度和经度,即坐标。 (请注意,页面不会随时刷新,这一切都发生在一个页面上。)
我想要做的是将前一个表单中的电子邮件字段值与纬度和经度一起传递,但我真的不能这样做因为我对 javascript 几乎是个菜鸟。
有没有办法在提交表单之前从“电子邮件”字段声明一个全局变量,以便我稍后可以使用它与纬度和经度参数一起传递。或者也许有更简单的解决方案?
预先非常感谢您!
这是我的 jquery 表单的代码
$(document).ready(function() {
var options = {
target: '#total',
clearForm: true,
beforeSubmit: radio,
success: social1
};
$("#perm").ajaxForm(options);
});
function radio(formData, jqForm, options) {
if ($('input:radio').is(':checked')) {
} else {
alert('choose gender!');
return false;
}
var form = jqForm[0];
if (form.year.value <= form.yob.value) {
alert('choose another year!');
return false;
}
};
function social1() {
$("#map").delay(700).slideDown("slow");
$("#accordion").slideUp("slow");
};
这是按钮代码
<form id='perm' action='add.php?stay=perm' method='post' onSubmit="return checkForm(this);">
I'm using a Jquery form on my website. The from is pretty much simple with the usual fields (name, email, dob etc.). After user presses register button, the form is submitted to the php file using Jquery from's 'ajaxForm' parameter. After that, the form slides out and the google map slides in asking customer to select his current location by dragging the marker on the map.
After the marker is put in the required place, customer can click "Submit" button and 2 values will be passed to another php file : latitude and longitude, ie coordinates. (please note that page does not refreshes at any time, this all happening on one page.)
What I want to do is to pass the email field value from the previous form together with latitude and longitude, but I can't really do that because I'm pretty much a noob at javascript.
Is there a way to declare a global variable from the field 'email' before submitting the form, so I could later use it to pass together with the latitude and longitude parameters. Or maybe there's even easier solution?
Thank you very much in advance!
here's the code of my jquery form
$(document).ready(function() {
var options = {
target: '#total',
clearForm: true,
beforeSubmit: radio,
success: social1
};
$("#perm").ajaxForm(options);
});
function radio(formData, jqForm, options) {
if ($('input:radio').is(':checked')) {
} else {
alert('choose gender!');
return false;
}
var form = jqForm[0];
if (form.year.value <= form.yob.value) {
alert('choose another year!');
return false;
}
};
function social1() {
$("#map").delay(700).slideDown("slow");
$("#accordion").slideUp("slow");
};
And here's the button code
<form id='perm' action='add.php?stay=perm' method='post' onSubmit="return checkForm(this);">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已经在使用 beforeSubmit 方法。稍微展开一下。这是捕获电子邮件地址的好位置。所以你最终会遇到这样的情况(未经测试):
You are already using the beforeSubmit method. Expand it a little bit. It is a fine location to catch the email address. So you end up with a situation like this (untested):
如果您只是隐藏表单而不刷新页面,则先前表单输入的电子邮件仍然可用(即您不需要声明全局变量来存储电子邮件)。例如,
If you simply hide the form without refreshing the page, the email input from the previous form is still available (i.e you don't need to declare a global variable to store the email). For example,