I am trying to build a table (using sql) based on the selections selected in a few multiple select boxes. Here is my javascript/jquery code:
function make_table(whichButton)
{
console.log("Whichbotton = " + whichButton);
//var prog = $("#program option:selected").val().join(" ");
var prog = $("#program").val() || [];
console.log("prog first= " + prog);
prog = prog.join(" ");
console.log("prog second= " + prog);
var sch = $("#school").val() || [];
sch = sch.join(" ");
var trm = $("#term").val() || [];
trm = trm.join(" ");
var ext = $("#extension").val() || [];
ext = ext.join(" ");
My understanding is that val() gets an array of all the selections, and the join function returns a string separating the values with the separator. But something isn’t right. The console.log says that the variable prog doesn’t have a value (or it just blank) even after I did the join. What is wrong?
Also, I coded each variable as being equal to ).val() || [];… I did this because thats how the example on the jquery site did it. But what does it mean? The jquery specifications say that if the array is empty then it reurns null as the default value, what does || [] mean?
|| [] means that if the val returns null, then to instead choose an empty array to be the element.
it means the same as:
as for your problem, you need to make sure your val() are returning correctly. try logging $(“#term”).val() and see if its returning what you expect it to return. if it is, you know you are doing something wrong elsewhere, though I don’t see anything offhand