Do this:
When loading the page run an ajax by posting the id to a php script, then retrieve the value of the id in your php by the variable $_GET['id']
, inside it a select in the database filtering by the sent id, finally load the information and print the response in json.
In your html:
<input type="hidden" id="produto_id" value="<?php echo $_GET['id']; ?>" />
In your javascript do:
$(document).ready(function (){
$.get("loadValue.php",{id : $('#produto_id').val()},function(data,status){
if(data == 'success'){
var arr = $.parseJSON(data);
$('#nome_produto').val(arr.nome);
$('#descricao').val(arr.texto);
}
});
});
$ (Documento).ready()
A page can not be safely manipulated until the document is "done". JQuery detects this state of readiness for you. The code included in the interior
$( document ).ready()
will only run once the Document Object Model (DOM) page is ready for the JavaScript code to execute. The code included in
$( window ).on("load",function() { ... })
will run once the entire page (images or iframes), not just DOM, is ready.
Now if you just want to display the input text fields when loading the page, the answer above is also good. Just load the id coming by get into a field of type hidden then using document.ready display the text fields if the value attribute has value.