i have a page , and when the page is started i get data using php like this
<?php $data = $this->data;?>
and then i want to put that data on the select tags , i mean the select tags will be defined when the page is opened and without any click from the user, i thing this will be like this
$(document).ready(function(){
$("#Id").val(data);
});
but my problems is that the jQuery function is on another file , i mean not on the html file , so how can i send that data i got from php on html to jQuery file
i have html page that used php to get some data
i have js file , i want to use that data on
if i can’t explain my problem , tell me to put the code
some code
html
<?php
$questionInfo = $this->questionInfo->fetch();
?>
<li>
<label>Type</label>
<select name="type"class="TypeSelector"></select>
<span class="errorMessage"></span>
</li>
jQuery
$.getJSON("http://localhost/Mar7ba/Type/getAllTypes/TRUE",function(data){
var options = '';
options+="<option>Select Type</option>";
for(var i=0;i<data.length;i++){
options += "<option value='"+data[i]+"'>"+data[i]+"</option>";
}
if($("#addPlace #apTypeSelect").length){
$("#addPlace #apTypeSelect").html(options);
}
if($('.TypeSelector').length){
$('.TypeSelector').html(options);
$('.TypeSelector').val("<?php echo $questionInfo['typeName']; ?>");
}
});
on jQuery , check the last line of my code
that is what i want to do , but questionInfo is not identified
I CAN”T USE JS ON MY HTML PAGE , BECAUSE ALL MY WEBSITE HAVE THE SAME HEADER AND SO EVERY PAGE STARTS FROM THE BODY“ , NOT FROM “
According to you edit:
JS code:
and last line of your code: