Old Javascript/AJAX to Jquery/Ajax

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Old Javascript/AJAX to Jquery/Ajax

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Old Javascript/AJAX to Jquery/Ajax

Post 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'));
});
Post Reply