Welcome Guest, Not a member yet? Register   Sign In
Keyup function doesn't work
#1

This script work perfectly on procedural, but in ci4, 'keyup' function doesn't work ?


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $("#search").keyup(function() {
    $.ajax({
      url: 'backend.php',
      type: 'post',
      data: {search: $(this).val()},
      success: function(result) {
        $("#result").html(result);
      }
    });
  });
});
</script>

Is there somebody would like to help me please.. ?
Reply
#2

CodeIgniter url is  [ controller/method ].

Code:
<script>
var xTriggered = 0;
$( "#target" ).keyup(function( event ) {
  xTriggered++;
  var msg = "Handler for .keyup() called " + xTriggered + " time(s).";
  $.print( msg, "html" );
  $.print( event );
}).keydown(function( event ) {
  if ( event.which == 13 ) {
    event.preventDefault();
  }
});

$( "#other").click(function() {
  $( "#target" ).keyup();
});
</script>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

[quote pid="398183" dateline="1657349768"]
Thanks dude, its work, but something else happens. The #inputSearch called (showed up) twice ?
[/quote]
[quote pid="398183" dateline="1657349768"]
I'm sorry but I need your solutions again ?
[/quote]
Reply
#4

Post your new code here so that we can see it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

I'm sorry but I still use my own code, I just follow ur instructions to use ci url to controller/method

<form action="" method="post">
<div class="container mt-2">
<div class="row g-2">
<div class="input-group input-group-sm mb-2">
<input type="text" class="form-control" id="cari" name="cari" placeholder="search city or region.." maxlength="16" size="35%">
<button class="btn btn-success" type="button" name="search" id="search"">Submit</button>
</div>
<hr class="mb-0">
<div class="row" name="result" id="result"></div>
<hr class="mb-0">
<small class="text-muted mt-0 pt-0">Made with ? <a href="/">CodeIgniter</a></small>
</div>
</div>
</form>

When I click submit, this whole form appears again below the result div between <hr class="mb-0">
Reply
#6

Just to add to the above, it's not a good idea to do a round trip to the server on keydown, look into 'debouncing' if that is your intended behaviour.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB