0
<?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.

2
  • 1
    You'll have to make an AJAX call to find out as the seat may have been booked by the time the button's clicked. Commented May 19, 2017 at 16:35
  • can you provide me some link ? im totaly new to this stuff Commented May 19, 2017 at 16:37

2 Answers 2

1

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

It worked .. thank you so much.. but how do i check these values db?
if user selects A1 .. to check if its reserved or not?
@Rizwan To do this, I'd recomend using AJAX to call another PHP file to check in your DB. If you want to learn more about AJAX requests, here is a simple tutorial.
<?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
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.