目标:
我希望用户在表单中输入信息,然后我将使用该信息生成不同的结果。
这是我的代码:
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 语句然后使用一个变量来为不同的选择存储一个特殊的“数字”,然后这个数字将被用来生成结果页面
例如:
用户选择消费、实时数据和一天结束的数据,可以说是选择 1
用户点击提交,结果页面将显示特殊链接/文章。
最佳答案
有很多验证脚本可以完全按照您的意愿进行操作 - 不要重新发明轮子....去拿一个并使用它:
原型(prototype):http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
JQuery : http://bassistance.de/jquery-plugins/jquery-plugin-validation/
唯:http://www.yuiblog.com/blog/2009/12/03/yui-3-gallery-form-module/
关于javascript - 使用 js 验证表单的最简单/最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7714346/