<?php
for ($i=1; $i <10 ; $i++) {
$A='A'.$i;
echo "<button onclick='selectSeat(id)' id='$A'>".$A."</button>";
}?>
<script type="text/javascript">
function selectSeat (id)
{
alert ("Button pressed ".id);
}
</script>
above is my seating map.... i want to check if if seat is reserved or not in DB through php but i don't know how to get it done through java script. i'm using java script to prompt user in if seat is reserved or not.
-
1You'll have to make an AJAX call to find out as the seat may have been booked by the time the button's clicked.tadman– tadman2017年05月19日 16:35:13 +00:00Commented May 19, 2017 at 16:35
-
can you provide me some link ? im totaly new to this stuffRizwan– Rizwan2017年05月19日 16:37:12 +00:00Commented May 19, 2017 at 16:37
2 Answers 2
I don't know if it's just a typo, but you are using the wrong operator to concatenate strings in javastring:
alert ("Button pressed ".id);
Should be
alert ("Button pressed "+id);
Sign up to request clarification or add additional context in comments.
4 Comments
Rizwan
It worked .. thank you so much.. but how do i check these values db?
Rizwan
if user selects A1 .. to check if its reserved or not?
Rizwan
<?php for ($i=1; $i <10 ; $i++) { $Seat='A'.$i; echo "<button onclick='selectSeat(id)' id='$Seat'>".$Seat."</button>"; } ?> <script type="text/javascript"> function selectSeat (id) { var Seat= $('#id'); alert ("Button pressed "+Seat); } </script
One way is to create a hidden input field using PHP with the value you want to send to javascript. Then you can get the value with javascript (either vanilla or jQuery) using $('#hidden-field').val() (for example).
answered May 19, 2017 at 16:36
Robert Taussig
5912 silver badges11 bronze badges
Comments
default