Update tag in page, when user changes his selection, with PHP and jQuery -
i need update post image, whenever user changes selection in "select html tag".
i'm trying use jquery , php in order that.
i need id of option user selected.
than want use id image url (using wordpress function).
finally, i'd add "url" in image tag.
this code:
<script type="text/javascript"> $(function(){ $('#select2').select2(); $('#select2').on('change', function() { var country = $('#select2 option:selected').val(); <?php $the_id = 'i need here id selceting in dropdpwn'; $url=wp_get_attachment_url(get_post_thumbnail_id($the_id)); ?> $(".countryvalue").html('<img width="80px" src="<?php echo $url; ?>" />'); }); }); </script> <div class="countryvalue" ></div> <select id="select2" name="marv_the_author"> <option value="0">--select author--</option> <option value="100">test</option> <option value="101">eeeee</option> </select>
you should use ajax that. change jquery function send ajax call, , create php page proccessing call , sending proper url.
your jquery function (notice page has no php script on it, can leave simple html page):
$(document).ready(function(){ $('#select2').on('change', function() { var country = $('#select2 option:selected').val(); $.ajax({url: "getimageurl.php?id=" + country, success: function(result){ $(".countryvalue").html('<img width="80px" src="' + result + '" />'); }}); }); }); create different php page this:
<?php $id = $_request["id"]; $url=wp_get_attachment_url(get_post_thumbnail_id($id)); echo $url;
Comments
Post a Comment