This is my first post on stack overflow, but as a novice I visit it often for answers but on this question I can't find an existing answer that helps me - because of my limited knowledge.
这是我关于堆栈溢出的第一篇文章,但作为一个新手,我经常访问它以获得答案,但在这个问题上,我找不到一个可以帮助我的现有答案 - 因为我的知识有限。
My website uses a prebuilt shop application - for which support is no longer available - which I have modified extensively over a number of years. There are checkout pages which feature a dropdown for Country and a second dependent dropdown for State.
我的网站使用预先构建的商店应用程序 - 不再提供支持 - 我已经对其进行了多年的广泛修改。有结帐页面,其中包含国家/地区的下拉列表和国家/地区的第二个相关下拉列表。
I removed the dropdowns entirely a long time ago because of a problem behaviour which I couldn't fix but now I have to reinstate the dropdowns (and their problem code) because my payment gateway is changing to a standardised country code and state code requirement.
我很久以前删除了下拉列表,因为我无法修复问题,但现在我必须恢复下拉列表(及其问题代码),因为我的支付网关正在变为标准化的国家/地区代码和州代码要求。
What happens is that when a selection is made from the Country dropdown, the code submits the form before a selection can be made from the States dropdown; at this point the browser puts up an alert asking for confirmation that you want to leave the page you are on.
所发生的情况是,当从“国家/地区”下拉列表中进行选择时,代码会在可以从“州”下拉列表中进行选择之前提交表单。此时,浏览器会发出警告,要求您确认是否要离开您所在的页面。
If you answer 'No' then you are stuck because the States dropdown remains empty and in any case the form's buttons (next, back, cancelled) now do nothing. On the other hand if you answer 'Yes' then the next checkout form is loaded in the browser and in that form you have to use the Back button to go back to the first form where the States dropdown is now populated and you can now make a selection, then use the 'next' button etc. Clearly not a viable process for a user because most will answer 'no' and simply get stuck.
如果你回答“否”,那么你就会陷入困境,因为状态下拉列表仍然是空的,无论如何表格的按钮(下一步,后退,取消)现在什么都不做。另一方面,如果您回答“是”,则下一个结帐表单将加载到浏览器中,并且在该表单中您必须使用“返回”按钮返回到现在填充“州”下拉列表的第一个表单,您现在可以选择,然后使用“下一步”按钮等。显然,对于用户来说,这不是一个可行的过程,因为大多数人会回答“否”而只是卡住了。
Here's the relevant part of the code:
这是代码的相关部分:
<tr>
<td class="KT_th"><label for="country_ord">Country:</label></td>
<td>
<select name="country_ord" id="country_ord" onChange="submitMe(this)">
<option value="" >Choose one...</option>
<?php
do {
?>
<option value="<?php echo $row_rsCountry['iso2_cnt']?>"<?php if (!(strcmp($row_rsCountry['iso2_cnt'], $row_rsorder_ord['country_ord']))) {echo "SELECTED";} ?>>
<?php echo $row_rsCountry['name_cnt']?></option>
<?php
} while ($row_rsCountry = mysql_fetch_assoc($rsCountry));
$rows = mysql_num_rows($rsCountry);
if($rows > 0) {
mysql_data_seek($rsCountry, 0);
$row_rsCountry = mysql_fetch_assoc($rsCountry);
}
?>
</select>
<?php echo $tNGs->displayFieldError("order_ord", "country_ord"); ?>
</td>
</tr>
<tr>
<td class="KT_th"><label for="state_ord">State (REQUIRED for USA only):</label (optional)></td>
<td>
<select name="state_ord" id="state_ord">
<option value="">Choose one ...</option>
<?php
do {
?>
<option value="<?php echo $row_rsStates['code_sta']?>"<?php if (!(strcmp($row_rsStates['code_sta'], $row_rsorder_ord['state_ord']))) {echo "SELECTED";} ?>><?php echo $row_rsStates['name_sta']?></option>
<?php
} while ($row_rsStates = mysql_fetch_assoc($rsStates));
$rows = mysql_num_rows($rsStates);
if($rows > 0) {
mysql_data_seek($rsStates, 0);
$row_rsStates = mysql_fetch_assoc($rsStates);
}
?>
</select>
<?php echo $tNGs->displayFieldError("order_ord", "state_ord"); ?>
</td>
</tr>
<tr class="KT_buttons">
<td colspan="2">
<input type="button" onClick="MM_goToURL('parent','index.php?mod=cartview');return document.MM_returnValue" value="< Previous">
<input type="submit" name="KT_Update1" id="KT_Update1" value="Next >">
<input name="button_cancel" type="button" value="Cancel" onClick="document.location = 'index.php?mod=cartview'">
<input type="hidden" name="validate_form" value="1">
</td>
</tr>
</table>
</form>
<script>
function submitMe(el)
{
var frm = el.form;
frm.action = window.location.href;
frm.elements.state_ord.selectedIndex = 0;
frm.elements.validate_form.value = 0;
KT_FVO = {};
frm.elements.KT_Update1.click();
}
</script>
2 个解决方案
#1
0
to prevent submitting when the value of the pull-down is selected remove this:
为了防止在选择下拉值时提交,请删除:
onChange="submitMe(this)"
from this:
<select name="country_ord" id="country_ord" onChange="submitMe(this)">
to this:
<select name="country_ord" id="country_ord">
#2
0
On country selection, Don't submit the form. Simply place an Ajax call that will fill your states box. On selection of all the required params in the form, submit the form. Even if you still want to go for form submission on country selection, on submission check if all data you need like states is filled or not. if not, load the same page with states data for selected country. next time user will select states and submit, than check all required data like states is present, load the function or page where your other stuff with data is to be done.
在国家选择时,请勿提交表格。只需放置一个填充状态框的Ajax调用即可。在选择表格中所有必需的参数时,请提交表格。即使您仍想在国家选择上提交表单提交,在提交时检查您所需的所有数据是否已填写。如果没有,请使用所选国家/地区的状态数据加载同一页面。下次用户将选择状态并提交,而不是检查状态所需的所有必需数据,加载功能或页面,其中包含数据的其他内容。
#1
0
to prevent submitting when the value of the pull-down is selected remove this:
为了防止在选择下拉值时提交,请删除:
onChange="submitMe(this)"
from this:
<select name="country_ord" id="country_ord" onChange="submitMe(this)">
to this:
<select name="country_ord" id="country_ord">
#2
0
On country selection, Don't submit the form. Simply place an Ajax call that will fill your states box. On selection of all the required params in the form, submit the form. Even if you still want to go for form submission on country selection, on submission check if all data you need like states is filled or not. if not, load the same page with states data for selected country. next time user will select states and submit, than check all required data like states is present, load the function or page where your other stuff with data is to be done.
在国家选择时,请勿提交表格。只需放置一个填充状态框的Ajax调用即可。在选择表格中所有必需的参数时,请提交表格。即使您仍想在国家选择上提交表单提交,在提交时检查您所需的所有数据是否已填写。如果没有,请使用所选国家/地区的状态数据加载同一页面。下次用户将选择状态并提交,而不是检查状态所需的所有必需数据,加载功能或页面,其中包含数据的其他内容。