【发布时间】:2013-06-19 21:13:36
【问题描述】:
我有一个基本的客户信息表,我想使其更具交互性。这个想法是,如果用户选择的国家不是美国或加拿大,则状态选择会转到州文本框。我确信这可以只用 php 来完成,但已经使用 jquery 进行了辩论,但如果可能的话,我想避免它。这是我的表单示例:
<tr>
<td>
<input name="city" type="text" id="city" value="<?= $this->aBillingProf['cCity']; ?>" />
</td>
<td>
<select name="state" id="state" style="width:218px;position:relative;top:-4px;">
<? $s = strlen($this->aBillingProf['cState']) == 2 ? strtoupper($this->aBillingProf['cState']) : strtoupper(stateTranslate($this->aBillingProf['cState']));
echo stateSelect('both',$s); ?>
</select>
<input name="state" type="text" id="state" value="<?= $this->aBillingProf['cState']; ?>" />
/*The Idea being only one of the above options is available depending on what is selected from the country select */
</td>
</tr>
<tr>
<td>
<label for="zip">Zip / Postal Code</label>
</td>
<td>
<label for="country">Country</label>
</td>
</tr>
<tr>
<td>
<input name="zip" type="text" id="zip" maxlength="6" value="<?= $this->aBillingProf['cZip']; ?>" />
</td>
<td>
<select name="country" id="country" style="width:218px;position:relative;top:-4px;">
<?= AffiliateStore::countrySelect($this->aBillingProf['cCountry']); ?>
</select>
<!-- <input type="text" name="country" id="country" value="<?= $this->aBillingProf['cCountry']; ?>" /> -->
</td>
</tr>
感谢您的任何意见或建议
【问题讨论】:
-
请发布呈现的 HTML 而不是 PHP。
-
你试图捕获一个客户端事件,你需要客户端脚本,仅 php 做不到
-
"我相信这可以只用 php 完成" 不,它不能,除非你想在之间重新加载
-
正如 Dagon 所说,PHP 需要重新加载页面。优雅的解决方案将通过 JavaScript 事件实现。
-
这是 JavaScript 的工作
标签: php html forms javascript-events