使用js验证表单最简单/最好的方法是什么?
objective:
我希望用户在表单上输入信息,然后我将使用该信息生成不同的结果。使用js验证表单最简单/最好的方法是什么?
继承人我的代码:
http://jsfiddle.net/5HUVm/
<form id="form1" name="form1" method="post">
<table>
<tr>
<td>I am interested in:</td>
<td><input type="radio" name="choice" value="consume" id="consume"/> Cosuming and/or distributing OTC Markets data
</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="choice" value="extranet" id="extranet"/> Providing connectivity to OTC Markets(Extranet)</td>
</tr>
<tr>
<td>Data products:</td>
<td><input type="checkbox" name="realtime" value="realtime" id="realTime">Real-time data</td>
<td><input type="checkbox" name="otcdata" value="otcdata" id="compData">OTC Company Data</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="eodprice" value="eodprice" id="eod">End of Day Pricing Data</td>
<td><input type="checkbox" name="otccompliance" value="otccompliance" id="otcComp">OTC Compliance Data</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="otcsecurity" value="otcsecurity" id="otcSec">OTC Security Data</td>
<td><input type="checkbox" name="otcqhistory" value="otchistory" id="otcHist">OTC Quote History</td>
</tr>
<tr>
<td>Data use:</td>
<td>
<select name="products" id="prod">
<option value="select">Select</option>
<option value="personal">Personal Use Only</option>
<option value="distEx">Distribute Externally Only</option>
<option value="distIn">Distribute Internally Only</option>
<option value="distBoth">Distribute Externally & Internally Only</option>
</select>
</td>
</tr>
<tr>
<td>Firm type:</td>
<td>
<select name="firm" id="firm">
<option value="select">Select</option>
<option value="broker">Broker-dealer</option>
<option value="oms">Order Management System</option>
<option value="finanInfo">Financial Information Service/Portal</option>
<option value="service">Service Bureau</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="reset" id="re">
<input type="button" id="sub" value="Submit" onclick="valid(this)">
</td>
</tr>
</table>
</form>
所以你可以看到有复选框,单选按钮,下拉菜单。
什么是验证检查/选择的最佳方式?
我在想:
大量的if语句,然后使用一个变量来存储一个特殊的“数字”为遂作出不同的选择taht号码将被用于生成结果页
例如:
用户选择消费,实时数据和结束日期数据,可以说选择1 用户单击提交,结果页面将显示特殊链接/文章。
有很多验证脚本在那里,会做你想要什么做 - 不要重新发明轮子....去抢单,并使用它:
原型:http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
JQuery的:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
YUI:http://www.yuiblog.com/blog/2009/12/03/yui-3-gallery-form-module/
最简单的方法是使用某种形式的已被写入插件,但允许你定制:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
有很多验证脚本在那里,会做你想要什么做 - 不要重新发明轮子....去抢单,并使用它:
原型:http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
JQuery的:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
YUI:http://www.yuiblog.com/blog/2009/12/03/yui-3-gallery-form-module/
是的!很多if语句...真棒主意! :) – doNotCheckMyBlog
'
@程序员我发现了讽刺-.-! – iCodeLikeImDrunk
回答
有很多验证脚本在那里,会做你想要什么做 - 不要重新发明轮子....去抢单,并使用它:
原型:http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
JQuery的:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
YUI:http://www.yuiblog.com/blog/2009/12/03/yui-3-gallery-form-module/
最简单的方法是使用某种形式的已被写入插件,但允许你定制:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
相关问题