Page 1 of 1

Old Javascript/AJAX to Jquery/Ajax

Posted: Thu May 20, 2010 1:56 pm
by bla5e
Trying to convert these 2 lines into jquery but a little confused..

Code: Select all

function loopSelected(){
  var txtSelectedValues = '';
  var selObj = document.getElementById('selected_cats');
  var i;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
        txtSelectedValues += '&cats[]=' + encodeURI( selObj.options[i].value );
    }
  }
  return txtSelectedValues;
}

var cats = loopSelected(document.getElementById('multipledropdown'));
var pub = encodeURI(document.getElementById('singledropdown').options[document.getElementById('singledropdown').options.selectedIndex].value);
I think I have converted var pub correctly, but not sure...

Code: Select all

var pub = encodeURI( $('#singeldropdown').val() );
Anyhelp is awesome help! New to jquery, and javascript too lol

Re: Old Javascript/AJAX to Jquery/Ajax

Posted: Thu May 20, 2010 5:06 pm
by kaszu
Looks good, here's for cats (didn't tested, but should work):

Code: Select all

var cats = '';
$('#selected_cats option:selected').each(function () {
    cats += '&cats[]=' + encodeURI($(this).attr('value'));
});