Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

Standalone search module - passing selected value as parameter

0 votes
45 views
added Mar 21 in Plugins by LC Marshal Captain (22,730 points)
edited Apr 2 by LC Marshal
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="../sites/all/themes/markone/assets/css/iframe/edgemarkets.css?v3">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<body>
  <div class="module-wrapper">
    <div class="logo-wrapper">
      <div class="row no-gutters">
        <div class="col-md-6 col-6">
          <a href="https://lazacode.org" target="_blank" title="Lazacode">
            <img class="logo ep" src="/sites/all/themes/markone/logo_white.png" alt="Home">
          </a>
        </div>
        <div class="col-md-6 col-6">
          <a href="https://hormart.com" target="_blank" title="Hormart">
            <img class="logo hormart" src="<?php echo $standalone_asset . 'hormart/hm-logo-white.png'; ?>" alt="Home">
          </a>
        </div>
      </div>
      
    </div>
    <div class="container">
      <div class="search-wrapper">
        <!-- <h1 class="title text-center">Find your perfect home.</h1> -->

        <div class="form-group">
          <select class="form-control" id="search-states" name="search-states">
            <!-- <option selected="" value="" disabled>Select states</option> -->
            <option value="Selangor">Selangor</option>
            <option value="Kuala Lumpur">Kuala Lumpur</option>
            <option value="Penang">Penang</option>
            <option value="Johor">Johor</option>
            <option value="Perak">Perak</option>
            <option value="Negeri Sembilan">Negeri Sembilan</option>
             <option value="Sarawak">Sarawak</option>
            <option value="Kedah">Kedah</option>
            <option value="Pahang">Pahang</option>
            <option value="Melaka">Melaka</option>
            <option value="Sabah">Sabah</option>
            <option value="Terengganu">Terengganu</option>
            <option value="Kelantan">Kelantan</option>
            <option value="Putrajaya">Putrajaya</option>
            <option value="Perlis">Perlis</option>
            <option value="Labuan">Labuan</option>
          </select>

          <div class="row">
            <div class="col-md-6 col-6">
              <select class="form-control" id="beds" name="bed-count">
                <option selected="" value="" disabled>No of beds</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
              </select>
            </div>
            <div class="col-md-6 col-6">
              <select class="form-control" id="pricebuy" name="pricebuy">
                <option selected="" value="" disabled>Budget</option>
                <option value="100000">Max 100k</option>
                <option value="200000">Max 200k</option>
                <option value="400000">Max 400k</option>
                <option value="600000">Max 600k</option>
                <option value="800000">Max 800K</option>
                <option value="1000000">Max 1M</option>
                <option value="5000000">> 1M</option>  
              </select>

              <select class="form-control" id="pricerent" name="pricerent" style="display: none;">
                <option selected="" value="" disabled>Budget</option>
                <option value="1000">Max 1k</option>
                <option value="2000">Max 2k</option>
                <option value="3000">Max 3k</option>
                <option value="5000">Max 5k</option>
                <option value="8000">Max 8K</option>
                <option value="9000">Max 9K</option> 
              </select>
            </div>
          </div>

          <div class="row">
            <div class="col-md-6 col-6">
              <div class="checkbox-half">
                <div class="radio">
                  <input id="check-buy" type="radio" name="purchase" value="buy" class="listingtype" checked="checked">
                  <label for="check-buy">Buy</label>
                </div>
              </div>
              <div class="checkbox-half">
                <div class="radio">
                  <input id="check-rent" type="radio" name="purchase" value="rent" class="listingtype">
                  <label for="check-rent">Rent</label>
                </div>
              </div>
            </div>
            <div class="col-md-6 col-6">
              <button type="button" class="btn btn-primary btn-block" id="searchProp">Search</button>
            </div>
          </div>

        </div>
      </div>

      <div class="news-card">
        <!-- <h1 class="title text-center">Latest property news</h1> -->
        <?php 
          function time_elapsed_string($datetime, $full = false) {
              $now = new DateTime;
              $ago = new DateTime($datetime);
              $diff = $now->diff($ago);

              $diff->w = floor($diff->d / 7);
              $diff->d -= $diff->w * 7;

              $string = array(
                  'y' => 'year',
                  'm' => 'month',
                  'w' => 'week',
                  'd' => 'day',
                  'h' => 'hour',
                  'i' => 'minute',
                  's' => 'second',
              );
              foreach ($string as $k => &$v) {
                  if ($diff->$k) {
                      $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
                  } else {
                      unset($string[$k]);
                  }
              }

              if (!$full) $string = array_slice($string, 0, 1);
              return $string ? implode(', ', $string) . ' ago' : 'just now';
          }
        ?>
        <div class="news-card-listing">
          <?php foreach($results as $row) : ?>
            <div class="row no-gutters single-card">
              <div class="col-md-4 col-4"><a href="/<?php print $row->path; ?>" target="_blank"><?php print $row->field_image; ?></a></div>
              <div class="col-md-1 col-1"></div>
              <div class="col-md-7 col-7">
                <!-- <p class="news-label"><?php print $row->field_category; ?></p> -->
                <h4 class="news-title"><a href="/<?php print $row->path; ?>" target="_blank"><?php print $row->node_title; ?></a></h4>
                <?php 
                  $newsdate = $row->node_created;
                  $timeAgo = date("F j, Y", substr($newsdate, 0, 10)); 
                ?>
                <p class="news-date"><?php print time_elapsed_string($timeAgo); ?></p>
              </div>
            </div>
          <?php endforeach; ?>
          <a class="no-underline" href="<?=$base_url?>/news" target="_blank"><div class="more-property-news"><button type="button" class="btn btn-primary btn-block">More property news ></button></div></a>
        </div>
      </div>
  </div>
</body>
</html>

<script>
$(document).ready(function(){
  var listingtype = 'buy';
  $('.listingtype').on('click',function(e){
    var id = $(this).attr('id');
    if (id == 'check-buy'){
      listingtype = 'buy';
      $('#pricerent').hide();
      $('#pricebuy').show();
    } else {
      listingtype = 'rent';
      $('#pricebuy').hide();
      $('#pricerent').show();
    }
  })

  $('#searchProp').on('click', function(e){
      e.preventDefault();
      var url = $(this).attr('href'),
          epDomain = "https://lazacode.org/search-category?";
          stateParam = '&state=',
          bedParam = '&bedroom_min=',
          priceParam = '&asking_price_max=',
          paramRent = '&listing_type=rental',
          statesVal = $('[name="search-states"]').val(),
          bedVal = $('[name="bed-count"]').val(),
          states = stateParam+statesVal,
          bed = bedParam+bedVal,
          epLink = epDomain+states;

      var paramListType;
      if ($('#check-rent').is(':checked')) { 
        paramListType = '&listing_type=rental';
      }
      else if ($('#check-buy').is(':checked')) { 
        paramListType = '';
      }
      var priceVal;
      if (paramListType == '&listing_type=rental') {
        priceVal = $('#pricerent').val();
      }
      else {
        priceVal = $('#pricebuy').val();
      }
      var price = priceParam+priceVal;

      if(statesVal && bedVal && priceVal && paramListType ){
        window.open(epLink+bed+price+paramListType);
      }
      else if(statesVal && bedVal && paramListType ){
        window.open(epLink+bed+paramListType);
      }
      else if(statesVal && bedVal && priceVal ){
        window.open(epLink+bed+price);
      }
      else if(statesVal && bedVal ){
        window.open(epLink+bed);
      }
      else if(statesVal && priceVal && paramListType ){
        window.open(epLink+price+paramListType);
      }
      else if(statesVal && priceVal ){
        window.open(epLink+price);
      }
      else if(statesVal && paramListType ){
        window.open(epLink+paramListType);
      }
      else if(statesVal) {
        window.open(epLink);
      }
  });
});
</script>

 

1 Response

0 votes
responded Apr 26 by LC Marshal Captain (22,730 points)
$(document).ready(function(){
  var listingtype = 'buy';
  $('.listingtype').on('click',function(e){
    var id = $(this).attr('id');
    if (id == 'check-buy'){
      listingtype = 'buy';
      $('#pricerent').hide();
      $('#pricebuy').show();
    } else {
      listingtype = 'rent';
      $('#pricebuy').hide();
      $('#pricerent').show();
    }
  })

  $('#searchProp').on('click', function(e){
      e.preventDefault();
      var url = $(this).attr('href');
      var epDomain;
      if ($('#check-rent').is(':checked')) {
        epDomain = 'https://lazacode.org/rent?';
      }
      else if ($('#check-buy').is(':checked')) {
        epDomain = 'https://lazacode.org/buy?';
      }
      var stateParam = '&state=',
          bedParam = '&beds=',
          priceParam = '&price_max=',
          statesVal = $('[name="search-states"]').val(),
          bedVal = $('[name="bed-count"]').val(),
          states = stateParam+statesVal,
          bed = bedParam+bedVal,
          epLink = epDomain+states,
          trackParam = '&wref=edgemarkets';
      
      var priceVal;
      if (epDomain == 'https://lazacode.org/rent?') {
        priceVal = $('#pricerent').val();
      }
      else {
        priceVal = $('#pricebuy').val();
      }
      var price = priceParam+priceVal;

      if(statesVal && bedVal && priceVal ){
        window.open(epLink+bed+price);
      }
      else if(statesVal && bedVal ){
        window.open(epLink+bed);
      }
      else if(statesVal && bedVal && priceVal ){
        window.open(epLink+bed+price);
      }
      else if(statesVal && bedVal ){
        window.open(epLink+bed);
      }
      else if(statesVal && priceVal ){
        window.open(epLink+price);
      }
      else if(statesVal && priceVal ){
        window.open(epLink+price);
      }
      else if(statesVal ){
        window.open(epLink);
      }
      else if(statesVal) {
        window.open(epLink);
      }
  });
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...