GuitarGod Posted August 16, 2013 Share Posted August 16, 2013 Hi all, I'm currently using jQuery's load function to send/load data into a page element, but I'm having trouble figuring out how to send dynamic data. var option_count = $( '#opt_count' ).val(); // This number is subject to change on every page var opts = ''; for ( i = 0; i < option_count; i++ ) { opts = opts+'&option_'+i+'='+$( '#option_'+i ).val(); } // So the data above could be &option_0=7&option_1=4&option_2=9 etc // but I can't seem to send option as an individual parameter // I've tried $( '#contain' ).load( 'receiver.php', { page_no : "2"+opts, }); // I've also tried $( '#contain' ).load( 'receiver.php', { page_no : "2", opts }); // What I'm trying to convey is $( '#contain' ).load( 'receiver.php', { page_no : "2", option_0 : 7, option_1 : 4 // etc etc.. }); However, the number of options and their values are dynamic and subject to change. Any ideas? Quote Link to comment Share on other sites More sharing options...
nogray Posted August 16, 2013 Share Posted August 16, 2013 Since you are making a query URL, just added the options to your link e.g. 'receiver.php?'+opts Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted August 16, 2013 Solution Share Posted August 16, 2013 var option_count = $( '#opt_count' ).val(); // This number is subject to change on every page var opts = {page_no:2}; for ( i = 0; i < option_count; i++ ) { opts['option_'+i] = $('#option_'+i).val(); } $( '#contain' ).load('receiver.php', opts); Create the opts object with the page_no option to start, then add each option_x property in the loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.