Sheldon Livingston
asked on
Set / retrieve value of array of inputs
I have a webpage with an array of inputs named 'myinputs'
Is there anyway to set the 4th one to the value of 15?
Is there anyway to set the 4th one to the value of 15?
ASKER
No joy... syntax error.
$("name='theVendorID'");
$("name='theVendorID'")[3].val('15');
alert($("name='theVendorID'")[3].val());
Sorry, you need to use eq() function:
if($("[name='myinputs']").length>3)
$("[name='myinputs']").eq(3).val('15');
Or, like this:$("[name='myinputs'].eq(3)").val('15');
ASKER
I've been guessing at this all night... googled 50 or so pages.
Maybe this is just too complex for jquery.
Anyway... eq failed too.
Syntax error. I'd thing this would be a good thing to update jquery to be able to do...
Maybe this is just too complex for jquery.
Anyway... eq failed too.
$("name='theVendorID'");
$("name='theVendorID'").eq(3).val('15');
alert($("name='theVendorID'").eq(3).val());
Syntax error. I'd thing this would be a good thing to update jquery to be able to do...
Please check my answer again. I have added the square brackets around [name='myinputs']. This is the correct syntax. Yours should be:
alert($("[name='theVendorID']").eq(3).val());
oralert($("[name='theVendorID']:eq(3)").val());
ASKER
Here's my code... still doesn't work.
$("[name='theVendorID']");
$("[name='theVendorID']").eq(3).val('15');
alert($("[name='theVendorID']").eq(3).val());
show how the input elements are created. Even better, create a JSFiddle, like this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jquery ios lame
Open in new window
This will return you the array of jQuery objects.You can then access the 4th element and set the value to 15, like this:
Open in new window
However, I suggest you test that the array size is at least 4:Open in new window