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?
Sheldon LivingstonConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
First of all you need to access the inputs by name. In jQuery you do it like this:
$("name='myinputs'")

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:
$("name='myinputs'")[3].val('15');

Open in new window

However, I suggest you test that the array size is at least 4:
if($("name='myinputs'").length>3)
  $("name='myinputs'")[3].val('15');

Open in new window

0
Sheldon LivingstonConsultantAuthor Commented:
No joy... syntax error.

$("name='theVendorID'");
$("name='theVendorID'")[3].val('15');
alert($("name='theVendorID'")[3].val());

Open in new window

0
chaauCommented:
Sorry, you need to use eq() function:
if($("[name='myinputs']").length>3)
  $("[name='myinputs']").eq(3).val('15');

Open in new window

Or, like this:
$("[name='myinputs'].eq(3)").val('15');

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Sheldon LivingstonConsultantAuthor Commented:
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.

$("name='theVendorID'");
$("name='theVendorID'").eq(3).val('15');
alert($("name='theVendorID'").eq(3).val());

Open in new window


Syntax error.  I'd thing this would be a good thing to update jquery to be able to do...
0
chaauCommented:
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());

Open in new window

or
alert($("[name='theVendorID']:eq(3)").val());

Open in new window

0
Sheldon LivingstonConsultantAuthor Commented:
Here's my code... still doesn't work.

$("[name='theVendorID']");
$("[name='theVendorID']").eq(3).val('15');
alert($("[name='theVendorID']").eq(3).val());

Open in new window

0
chaauCommented:
show how the input elements are created. Even better, create a JSFiddle, like this
0
chaauCommented:
Have a look at this
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sheldon LivingstonConsultantAuthor Commented:
jquery ios lame
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.