fahad
fahad

Reputation: 41

Need to pass value of php in jquery script

I need to pass the PHP retrieved value from database to Ajax function for further querying in database my code is given below.

The PHP Script:

$query = mysql_query("SELECT * FROM employee") or die(mysql_error());

while($res=mysql_fetch_assoc($query)){  
echo $res['emp_id'];   
$emp_id=$res['emp_id']

and submit button with id name-submit

The Javascript

$('input#name-submit').on('click',function(){ 
var empid = $('php echo $emp_id; ');
alert(empid);

the script is running just below the php script.

Upvotes: 0

Views: 59

Answers (1)

slugonamission
slugonamission

Reputation: 9632

Exactly as you are doing, but by putting the full opening tag in there. Change the second JS line to:

var empid = $('<?php echo $emp_id; ?>');

Upvotes: 4

Related Questions