I'm currently working on a website, where clicking "Enroll" on any event shown on the Schedules page would lead to an Enroll page, where a <select> drop-down list would automatically select a value based on parameters placed at the end of the url.
However, I'm having difficulty in making sure that the option with the value based on these parameters actually gets selected. After clicking an "Enroll" button, the drop-down list on the Enroll page doesn't show any text despite the parameters being present at the end of the URL.
Live URL: brain-train.com.ph/schedules. (Select anything on the dropdown menus on that page and click on any "Enroll" button.)
JS:
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
var service = $.urlParam('service');
var batch = $.urlParam('batch');
var appendURL = '?service=' + service + '&batch=' + batch;
var selectValue = $('.page-enroll .info').data('value');
if ( service !== undefined && batch !== undefined ) {
$('.page-enroll select[name="batch"]').val(service + '-' + batch);
}
valueon your options? val is not a valid/useful option attribute$('.page-enroll select[name="batch"]')when page-enroll is a class on the body tag