kit123321 Posted August 11, 2022 Share Posted August 11, 2022 when i click button .btnStart, i would like to INPUT class="stime" to have value $resp['start'] without page reload. but not work. any help? JS code $(".btnStart").click( function() { var tid = $(this).data("tid") $.get( "", {"ajax":"startBooking", "tid":tid}, function(resp) { $(".sdate[data-tid="+tid+"]").val(resp.sdate).show() $(".stime[data-tid="+tid+"]").val(resp.start).show() $(".bid[data-tid="+tid+"]").val(resp.bid) }, "JSON" ) $(this).hide() $(".btnFinish[data-tid="+tid+"]").show() }) PHP Handle AJAX ## Handle AJAX requests if ($_GET['ajax'] == 'startBooking') { $dt = new DateTime('now'); $start = $dt->format('Y-m-d H:i:s'); $st = $dt->format('H:i'); $sd = $dt->format('Y-m-d'); $stmt = $pdo->prepare("INSERT INTO table_booking (table_id, start_time) VALUES (?, ?)"); $stmt->execute( [ $_GET['tid'], $start ] ); $bid = $pdo->lastInsertId(); $resp = [ "bid" => $bid, "start" => $st, "sdate" => $sd ]; exit( json_encode($resp)); } HTML <input type='time' class='stime' value='$st' data-tid='{$r['tid']}'> Quote Link to comment https://forums.phpfreaks.com/topic/315165-when-clicked-the-value-can-not-pass-to-input-element-without-reload-page/ Share on other sites More sharing options...
kit123321 Posted August 11, 2022 Author Share Posted August 11, 2022 issue fixed. please help to delete it Quote Link to comment https://forums.phpfreaks.com/topic/315165-when-clicked-the-value-can-not-pass-to-input-element-without-reload-page/#findComment-1599234 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.