Toggle navigation
ADEPTSTATION
<p><strong>----------------------------------------------------------------------------------------------------</strong></p><p><strong>Required dependency files:</strong></p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><p>Latest Jquery </p><p> </p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><p><strong>Front - CSS</strong></p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><pre><code class="language-css"><style type="text/css"> .search_result{ border: 1px solid #ddd; position: absolute; width: inherit; background: #fff; z-index: 5; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; top: 35px; } .search_result .srchresulttitle{ padding: 7px !important; padding-bottom: 0 !important; } .search_result a:hover{ text-decoration: none; } .search_result a:hover .eachprod{ background-color: #eee; } .search_result .eachprod{ padding: 5px 10px; } .hide{ display: none; } </style></code></pre><p> </p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><p><strong>Front - Element</strong></p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><pre><code class="language-xml">Product search<br/> <div class="col-md-12 p-0"> <input class="form-control" type="text" id="prosearchboc" name="prosearchboc" placeholder="search product" onkeyup="searchProduct()"> <div class="search_result hide"></div> </div> <br/>&nbsp; </code></pre><p> </p><p> </p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><p><strong>Search Script</strong></p><p><strong>----------------------------------------------------------------------------------------------------</strong></p><p>Search based on kwyword</p><pre><code class="language-javascript"><script language="javascript" type="text/javascript"> {literal} function searchProduct(){ var search_data = document.getElementById('prosearchboc').value; var is_inside_mfg_suggesition = 0; $('#prosearchboc').on('focus', function(){ if($('.search_result').children('.srchresulttitle').length <= 1){ if($('.search_result .srchresulttitle').hasClass("no-result")){ $(".search_result").html('<div class="srchresulttitle no-result"><small><b>Search result</b></small></div><div class="col-md-12 eachprod">No result found</div>'); } } else { } $('.search_result').removeClass('hide'); }); $('#prosearchboc').on('blur', function(){ if(is_inside_mfg_suggesition == 0){ $('.search_result').addClass('hide'); }&nbsp; }); $('.search_result').on('mouseenter', function(){ is_inside_mfg_suggesition = 1; }); $('.search_result').on('mouseleave', function(){ is_inside_mfg_suggesition = 0; }); $.ajax( { type: "POST", url: "{/literal}{$base_url}{literal}product/search_product", data: {search_data: search_data}, success: function(return_data){ var html = JSON.parse(return_data); if(html.status != ''){ if(html.status == '1'){ var final_html = '<div class="srchresulttitle"><small><b>Search result</b></small></div>'; for (var i = 0; i < html.product_result.length; i++) { var current_prod = html.product_result[i]; final_html += '<a href="'+html.site_url+'product/search?k='+current_prod['keyword_name'].toLowerCase()+'&amp;i='+current_prod['keyword_id']+'"><div class="col-md-12 eachprod">'+current_prod['keyword_name']+'</div></a>'; } $(".search_result").html(final_html); $('.search_result').removeClass('hide'); } else if(html.status == '2'){ console.log("No result found."); $(".search_result").html('<div class="srchresulttitle no-result"><small><b>Search result</b></small></div><div class="col-md-12 eachprod">No result found</div>'); $('.search_result').removeClass('hide'); } else if(html.status >= '3'){ console.log("Invalid request. Please try again."); $(".search_result").html('<div class="srchresulttitle no-result"><small><b>Search result</b></small></div><div class="col-md-12 eachprod">No result found</div>'); $('.search_result').removeClass('hide'); } else { $(".search_result").html('<div class="srchresulttitle no-result"><small><b>Search result</b></small></div><div class="col-md-12 eachprod">No result found</div>'); $('.search_result').removeClass('hide'); } } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (XMLHttpRequest.readyState == 4) { // HTTP error (can be checked by XMLHttpRequest.status and XMLHttpRequest.statusText) if(textStatus === 'timeout'){ console.log("Failed from timeout."); } else { console.log("HTTP error."); } document.getElementById('fatching-result').style.display = 'none'; } else if (XMLHttpRequest.readyState == 0) { // Network error (i.e. connection refused, access denied due to CORS, etc.) if(textStatus === 'timeout'){ console.log("Failed from timeout."); } else { console.log("A network error occurred. Please try again."); } document.getElementById('fatching-result').style.display = 'none'; } else { // something weird is happening if(textStatus === 'timeout'){ console.log("Failed from timeout."); } else { console.log("Something weird is happening."); } document.getElementById('fatching-result').style.display = 'none'; } }, timeout: 20000, }).fail(function(jqXHR, textStatus){ document.getElementById('fatching-result').style.display = 'none'; }); } {/literal} </script></code></pre><p> </p>
Sub links
-
../
No sub links
×
Attachments
Page heading:
Product search
×
Page history
Page heading:
Product search