В примере в select выбираем option c нужным value (id — необходимое значение)
function InlineForm(id) {
var poluch=document.getElementById('poluch');
var poluch_o=poluch.options;
$("#poluch").find("option").removeAttr("selected");
for (i=0;i<poluch_o.length;i++) {
if (poluch_o[i].value==id) {
poluch[i].setAttribute("selected","selected");
poluch[i].selected=true;
}
}
}
javascript:
$(document).ready(function(){
var session;
var secpic=document.getElementById('secpic');
$.ajaxSetup({cache:false})
$.get('gs.php',{requested:'captcha'},function (data) {
session=data;
secpic.value=$.trim(session);
});
});
php:
session_start();
if (isset($_GET['requested'])) {
print $_SESSION[$_GET['requested']];
}
else {
print json_encode($_SESSION);
}
html:
<input type="hidden" id="secpic" name="secpic" value=""/>
http://stackoverflow.com/questions/2765175/how-to-get-session-variables-from-php-server-with-ajax-function-php-html-js-aj
Понадобилось для замены артибутов картинок hspace,vspace на отступы css margin (атрибуты добавлял ckeditor, но это перекрывается стилями).
$(document).ready(function(){
$('img[hspace]').each(function(){
var pixels=parseInt($(this).attr('hspace'));
if(isNaN(pixels)||pixels<1){
pixels=0;
}else{
pixels=pixels/2;
}
$(this).css('marginLeft',pixels+'px')
.css('marginRight',pixels+'px')
.removeAttr('hspace');
});
$('img[vspace]').each(function(){
var pixels=parseInt($(this).attr('vspace'));
if (isNaN(pixels)||pixels<1) {
pixels=0;
}else{
pixels=pixels/2;
}
$(this).css('marginTop',pixels+'px')
.css('marginBottom',pixels+'px')
.removeAttr('vspace');
});
});
http://heathnewmedia.com/2012/04/01/hspace-vspace-jquery-fix-for-wordpress/