0

I just want to ask. How can I pass a textfield values in a PHP variable within the same page? What I want is to get the variable and I will query this number to get the product's information.

Here's my code:

This is the link that

<td style='text-align: left'>
<a href="javascript:void(0)" onclick="$('#w').window('open')" data-value="<?php echo $itid ?>" class="id_prod"><?php echo $itemname; ?></a>
</td>

Below is my modal dialog:

<div id="w" class="easyui-window" title="Price History" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:500px;height:200px;padding:10px;">
<input type="text" value="" name="prod_id" value=""/> <!-- this will get the values -->

And below again is my jquery:

<script>
   $(".id_prod").click(function(){
   var id = $(this).attr('data-value');
   $('input[name="prod_id"]').val(id) //this will pass the value to my textbox
   });
</script>
rochellecanale
  • 205
  • 2
  • 8
  • 21

1 Answers1

0

You need to do this using Ajax. The reason is that your code PHP is resolved in the server, so when it arrives to the client side it is not gonna be executed any more. What is executed client side is JavaScript.

So, via Ajax you can connect with your server to retrieve the data that you want to get to update the field, and add this product information manipulating the DOM with JavaScript.

UPDATE: Or if it is not too much information and you don't want to use Ajax, you can print your PHP values into a JavaScript object, and use it then to manipulate the DOM. That would be something like this:
PHP:

echo "<script type=\"text/javascript\">\n";
echo "items = [";
//this sould be a for with your data and attributes
items+= "{itemname:'"+itemname+"', itemvalue:'"+itemvalue+"'},";
items+= "{itemname:'"+itemname2+"', itemvalue:'"+itemvalue2+"'}"
items+= "]";
echo "</script>\n";

JavaScript:

function clickLink (index){
 $("#container").append("NAME:"+ items[index].itemname);
}
Wood
  • 1,766
  • 1
  • 12
  • 10