目标:
我希望用户在表单上输入信息,然后我将使用该信息生成不同的结果。
这是我的代码:
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用户点击提交,结果页面将显示特殊的链接/文章。
有很多验证脚本会做你想做的事情——不要重新发明轮子。。。。去拿一个使用它:
原型: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/