0

I've created dynamic links with an editName(id) function

<a onclick="{editName(2); $('#editName').dialog('open');}" 
style="cursor: pointer; text-decoration: underline;">My Name</a>

In the above example My Name has an id=2

Now I can simply show an alert but how can I echo id through PHP?

function editName(id)
{
alert(id);
// <?php echo(id);?> 
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Marcel Marnix
  • 93
  • 1
  • 8

1 Answers1

0

It is not possible to assign javascript value to php untill and unless you give ajax call

So Create Hidden Value in Your HTML

<a onclick="{editName(2); $('#editName').dialog('open');}"
style="cursor: pointer; text-decoration: underline;">My Name</a>
<input type="hidden" id="name_id" value="<?php echo $nameId?> " />

function editName(id)
{
alert(id);
var id1 =  $("#name_id").val();
alert(id1)
// <?php echo(id);?> 
}