jQuery - Validate that two different <li>'s has been selected -


for online booking system have user put in pickup , destination postcode. problem user can search address, e.g. 'le115gu' , show multiple results. @ moment user can go next page of booking form without selecting address doesn't write address database. need put validation in there if user doesn't select li-addr-res either pickup or destination, prompted alert.

this happens if user searches postcode:-

enter image description here

so like:-

if(nextpgenum == 2) {    // code // if title="dropoff" , no li-addr-res selected   // or if title="pickup" , no li-addr-res selected   // alert("you must select pickup or dropoff address")  } 

i'm not sure how can achieve appreciated.

here html code dropoff.

 <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> 

as posted in comments, 1 option use list of radio buttons , check whether of them has been selected before continuing. on these lines:

$(document).ready(function(){   // on form submission   $('#submit_button').click(function() {     // check if @ least 1 of radio buttons named 'test' has been selected     if (!$("input[@name='test']:checked").val()) {        alert('nothing checked!');        return false;     }     else {       alert('one of radio buttons checked!');     }   }); }); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -