javascript でフォームを検証しようとしています。関数が適切に呼び出され、アラートが表示されますが、アラートで [OK] をクリックしてもフォームが送信されます。関数が false を返すことはありません。この質問が以前に尋ねられたのを見たことがありますが、うまくいった答えは見たことがありません。これでいくつかのJQueryモバイルを使用していますが、それが問題かもしれません。ボタンの入力タイプ=ボタンを変更しようとしましたが、フォームを送信することさえできません。
JavaScript関数は次のとおりです。
<script>
function validateInventoryform()
{
var sku=document.getElementById('sku_checkbox');
var entire=document.getElementById('entire_checkbox');
var inv=document.getElementById('inv');
if ((sku.checked==true && entire.checked==true))
{
alert("You may only choose one option to check customer inventory");
return false;
}
}
</script>
フォームは次のとおりです。
<div data-role="popup" id="popupQuery_inventory" data-theme='a' >
<div style="padding:10px 20px;">
<form action="inventory_inquiry.php" method="get" id="inv" onsubmit="return validateInventoryform()" >
<h3>Enter SKU</h3>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<legend>Choose Input Type:</legend>
<input type="checkbox" data-theme="a" name="sku_checkbox" id="sku_checkbox" value="off" checked="checked">
<label for="sku_checkbox">SKU</label>
<input type="checkbox" data-theme="a" name="entire_checkbox" id="entire_checkbox" value="off">
<label for="entire_checkbox">Entire Inventory</label>
</fieldset>
<label for="sku" class="ui-hidden-accessible">SKU:</label>
<input type="text" name="sku" id="sku" value="" placeholder="Item SKU" data-theme="a">
<input name="customer_id" type="hidden" value='<?php echo $customer_id; ?>'/>
<button type="submit" data-theme="b"/>Submit</button>
</form>
</div>
</div>
フォームのポップアップを呼び出す href を追加しています。それがこの問題と関係があるかどうかはわかりません。私のコードが複製され、問題なく動作しているという話をよく耳にします。私はそれを機能させることができず、問題全体を表現したいと考えています。
<ul data-role="listview" data-inset="true" data-theme="b">
<li><a href="#popupCustomer_alert" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Add Customer Alert</a></li>
<li><a href="#popupQuery_inventory" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Query Inventory</a></li>
<li><a href="#popupEdit_customer" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Edit Customer</a></li>
<li><a href="return_qr_code.php" >Get QR Code</a></li>
<li><a href="#popupDownload_inventory" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Download Inventory</a></li>
</ul>