Tuesday, 20 August 2013

jquery val is correct function?

jquery val is correct function?

The javascript in the code below is supposed to set some values in a form
equal to the variable selected[] (possible values for selected[i]: true,
false;) For sure, the code before has set the proper values for all
selected[i] elements.
However, the console shows the error 'productvalid: [object Object]'
(instead of a true or false). Am I reading or writing the values in the
wrong way? (I read and googled quite a bit about the jquery val() and
related functions like prop() and attr() but can figure out what goes
wrong. I also used the val() function in another part of code to write a
value to an input tag which does work).
Please your help...
Html code (the input type is rep:
<input type="hidden" id="productvalid1" name="productvalid[]"
value="false" />
<input type="hidden" id="productvalid2" name="productvalid[]"
value="false" />
<input type="hidden" id="productvalid3" name="productvalid[]"
value="false" />
Javascript code:
for(var i=0;i<nrofproducts;i++)
{
$("#productvalid"+i).val(selected[i]);
x = $("#productvalid"+i).val(selected[i]);
console.log("productvalid: "+x);
}

No comments:

Post a Comment