I currently have a javascript popup div that contains a select object that is populated from a POST variable that was generated from the main page. Is it efficient to pass data with html via post to pass data to a popup? Or is there a better way to do this?
main page
< ?php
require('testclass.php);
$obj = new testclass();
foreach ($obj->getlist as $listobj)
{
$output .= "<option>" . $listobj['name'] . "</option>";
?>
main page javascript
<script type=text/javascript">
$(document).ready(function () {
$("#a_popup").click(function () {
$("#div_popup").load("popup.php", {"list" : "<?php echo $output ?>"});
});
});
popup.php
<select> <?php echo $_POST['list'] ?> </select>
You can send data back to page and do something like this
<select name="what ever you want">
<option value=""></option>
<?php
foreach ($values_from_page_you_sent as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
?>
</select>
Something like this you can modify it according to your use values_from_page_you_sent are values that you send from some X page to this page.
Edit: if you are looking Jquery/JS based solution then that is another scenario which you can do some thing like this
jQuery.each(data, function(key, value) {
jQuery('select[name="' + populatedElement + '"]')
.append(jQuery("<option></option>")
.attr("value", key)
.text(value));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.