As I am new to this I would like your advice.
So far I have figured out two ways to populate form fields.
Say this is my html:
<input id="test" name="test" type="text">
As you see the id of each field matches the name.
When it's time to populate the field from Sql i could either do:
PHP:
<input id="test" name="test" type="text" value="<?php if(isset($SqlRequested['test'){echo $SqlRequested['test'];}">
and similarily write all the fields of my form...
or add this in the head part
JQUERY:
<script>
<?php echo "$(document).ready(function(){";
foreach ($SqlRequested as $id => $value){
echo "$('#" . $id . "').val(\"" . $value . "\");"
echo "};"
echo "});"
?>
</script>
besides the fact that the jQuery gives me some problems when the fields contain "enter/return" in them (which could be fixed by using .html or .text i guess)
Which one would you suggest, what are the drawbacks or pro's of each method?
Any improovements to the code?
Is there some other way i am missing?
Any suggestions on easily fixing the little problem mentioned above?
Thanx in advance.
Edit: I just noticed the jQuery .populate, which im guessing is something like my second way, you just need to get your data in a format of {'id':'value',...}