mahenda Posted September 27, 2019 Share Posted September 27, 2019 //php code <?php include_once('con.php'); if(!empty($_GET['search'])) { $search = $connect->prepare('SELECT * FROM posts WHERE title LIKE :search'); $search->bindValue(':search', '%'.$_GET['search'].'%', PDO::PARAM_STR); $search->execute(); ?> <?php while($row = $search->fetch()) {?> <li class="result" onClick="searchValue('<?php echo $row['title'];?>')"><?php echo $row['title'];?></li> <?php } ?> <?php } ?> //ajax $('#inputsch').keyup(function(){ $.ajax({ type: 'GET', url: 'fetch.php', data:'search='+$(this).val(), success: function(data){ $('#box').show(); $('#box').html(data); } }); }); }); function searchValue(val) { $('#inputsch').val(val); $('#box').hide(); } //search box <form action="search.php"> <input id="inputsch" type="text" name="search" placeholder="search..." autocomplete="off" autofocus> <button type="submit" value="search" >search</button> </form> <div id="box"></div> //the problem here is when i click the result is only added to input, but i want it to autosubmit Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/ Share on other sites More sharing options...
requinix Posted September 27, 2019 Share Posted September 27, 2019 If you want it to submit then make it submit. Fix the searchValue function so it does that. Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570011 Share on other sites More sharing options...
mahenda Posted September 27, 2019 Author Share Posted September 27, 2019 1 minute ago, requinix said: If you want it to submit then make it submit. Fix the searchValue function so it does that. an idea please Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570012 Share on other sites More sharing options...
requinix Posted September 27, 2019 Share Posted September 27, 2019 $.submit Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570013 Share on other sites More sharing options...
mahenda Posted September 29, 2019 Author Share Posted September 29, 2019 On 9/27/2019 at 10:30 PM, requinix said: $.submit Oh! If I'll remove onclick function which is there for getting value after clicking , isnt possible to get such value in in input using jQuery if yes why and how?! Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570061 Share on other sites More sharing options...
requinix Posted September 29, 2019 Share Posted September 29, 2019 You don't need to get the value. As far as I know. All you need to do is submit the form. Oh wait, you're not doing that. Your autocomplete function should put the value into the form. Click the LI, set it as the INPUT's value, and submit the form. Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570062 Share on other sites More sharing options...
mahenda Posted October 7, 2019 Author Share Posted October 7, 2019 On 9/29/2019 at 10:42 PM, requinix said: You don't need to get the value. As far as I know. All you need to do is submit the form. Oh wait, you're not doing that. Your autocomplete function should put the value into the form. Click the LI, set it as the INPUT's value, and submit the form. On 9/29/2019 at 10:42 PM, requinix said: You don't need to get the value. As far as I know. All you need to do is submit the form. Oh wait, you're not doing that. Your autocomplete function should put the value into the form. Click the LI, set it as the INPUT's value, and submit the form. very helpful thanks but what if i want to change the SELECT * FROM posts WHERE title LIKE :search to SELECT * FROM posts WHERE title LIKE :search OR author LIKE :search; and want to get both by using single list like <li class="result" onClick="searchValue('<?php echo $row['some value here'];?>')"><?php echo $row['some value here'];?></li> here the result on search will be //title will display on key up //author will display on key up instead of <li class="result" onClick="searchValue('<?php echo $row['title'];?>')"><?php echo $row['title'];?></li> <li class="result" onClick="searchValue('<?php echo $row['author'];?>')"><?php echo $row['author'];?></li> Quote Link to comment https://forums.phpfreaks.com/topic/309289-how-to-auto-submit-the-auto-suggested-result/#findComment-1570409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.