1

对于在线预订系统,我让用户通过邮政编码输入接送和目的地。问题是用户可以搜索一个地址,例如“LE115GU”,它会显示多个结果。目前,用户无需选择地址即可转到预订表格的下一页,因此不会将地址写入数据库。我基本上需要在其中进行验证,以便如果用户没有选择li-addr-res接送或目的地,他们会收到警报提示。

如果用户搜索邮政编码会发生这种情况:-

在此处输入图像描述

所以像: -

if(nextPgeNum == 2) { 

 // CODE // if title="Dropoff" and no li-addr-res is selected

 // or if title="Pickup" and no li-addr-res is selected

 // alert("You must select a pickup or dropoff address")

}

我只是不太确定如何实现这一目标,因此非常感谢任何帮助。

这是dropoff的HTML代码。

 <div id="cp-row-wrapper-dp" class="row-wrapper row-wrapper-addr-search" title="Dropoff">

    <div class="div-search-label left">

        <p class="a-topheader-infotext">

    <strong>Destination</strong>

    </p>

</div>

<div class="div-search-content div-content left div-subrow-style ui-corner-all">

    <input id="txt-dropoff-hn" class="input-txt-xxxsml input-txt-highlight addr-ho-input left" type="text" value="" maxlength="5" size="4" tabindex="3" name="txt-dropoff-hn">

    <input id="txt-dropoff" class="input-txt-xmed input-txt-highlight required validate-from-db addr-search-input txt-dropoff left default success" type="text" tabindex="4" name="txt-dropoff" autocomplete="off">

    <input class="hidden-lat-lng" type="hidden" value="">

    <input id="txt-hidden-dp" class="hidden-post-code" type="hidden" name="txt-hidden-dp" value="">

    <input class="hidden-route-leg" type="hidden" value="2">

    <button id="cp-search-dest" class="btn-med ui-button ui-state-default ui-button-text-only ui-corner-all btn-hover-anim btn-row-wrapper left ui-state-hover" name="btn-row-wrapper">Search</button>

    <ul class="ul-addr-res ul-result-view" style="visibility: visible; display: block;">

    <li class="li-addr-res">

    <p class="p-addr-res" style="cursor: pointer;" tabindex="0">PRINCE WILLIAM ROAD, LOUGHBOROUGH, LE115GU</p>

    </li>

    <li class="li-addr-res">


    <p class="p-addr-res" style="cursor: pointer;" tabindex="1">ARTHUR JONES MOTORS, 6A, PRINCE WILLIAM ROAD, LOUGHBOROUGH, LE115GU</p>

    </li>

    <li class="li-addr-res">

    <p class="p-addr-res" style="cursor: pointer;" tabindex="2">BROMAKIN LTD, 10, PRINCE WILLIAM ROAD, LOUGHBOROUGH, LE115GU</p>

    </li>

    <li class="li-addr-res">

    <p class="p-addr-res" style="cursor: pointer;" tabindex="3">C D M DUCTWORK, 17, PRINCE WILLIAM ROAD, LOUGHBOROUGH, LE115GU</p>

    </li>

    <li class="li-addr-res">

    <p class="p-addr-res" style="cursor: pointer;" tabindex="4">CHARNWOOD MOLECULAR, 13, PRINCE WILLIAM ROAD, LOUGHBOROUGH, LE115GU</p>

    </li>

    </ul>

    <div class="div-result-info div-pagenation-style" style="display: block;">

    </div>

</div>
4

2 回答 2

2

正如我在评论中发布的那样,一个选项是使用单选按钮列表并在继续之前检查是否已选择其中任何一个。这些线上的东西:

$(document).ready(function(){
  // On form submission
  $('#submit_button').click(function() {
    // Check if at least one of the radio buttons named 'test' has been selected
    if (!$("input[@name='test']:checked").val()) {
       alert('Nothing is checked!');
       return false;
    }
    else {
      alert('One of the radio buttons is checked!');
    }
  });
});
于 2013-07-23T10:48:14.577 回答
0

Every client side solution will be problematic because user can change client side scripts and settings. You could allow user to go to the next page and then check if database entry exists. If it does not exist, redirect him back to the previous step. Or you can check database entry when user clicks next ...

于 2013-07-23T10:45:27.903 回答