get value by name

how do i get value by name in jquery..
give example if u can ?
deepakabcAsked:
Who is Participating?
 
shanikawmCommented:
ok. Then try following html.

it will show

food1 = egg1 | food2 = egg2 | food3 = egg3 |
<html>
<head>
  <script src="jquery.js"></script>
  <script>
  $(document).ready(function(){
        var a=[];
        a=$("form > *");
        for (var i = 0; i < a.length; i++) {
                $("div").append(a.get(i).name+" = "+a.get(i).value+" | ");
        }
  });
  </script>
</head>
<body>
  <form>
  <input type="hidden" name="food1" value="egg1">
  <input type="hidden" name="food2" value="egg2">
  <input type="hidden" name="food3" value="egg3">
  </form>
  <div></div>
</body>
</html>

Open in new window

0
 
shanikawmCommented:
if the element is

<input type="hidden" name="myinput" value="myvalue" />

$(myinput).val() returns the value. No quotations.
0
 
deepakabcAuthor Commented:
inside form it's not working

i meanform tag
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
shanikawmCommented:
Ahh..  Then,  $(form.element).val();

e.g.

<form name="myform">
<input type="hidden" name="myinput" value="myvalue" />
</form>


$(myform.myinput).val() returns value.
0
 
deepakabcAuthor Commented:
what i want... i want to specify name in it  like

name = att1, name= att2, name=att3

then access all of them by for loop ....

0
 
shanikawmCommented:
Could you please explain bit more?

Say form is like follow

<form name="myform">
<input type="hidden" name="food" value="eggs">
<input type="hidden" name="drink" value="beer">
</form>

Then you need?
0
 
deepakabcAuthor Commented:
<form name="myform">
<input type="hidden" name="food1" value="eggs">
<input type="hidden" name="food2" value="beer">
<input type="hidden" name="food3" value="beer">
</form>

now i want to access all the name variable through for loop in jquery ...

for (i=0; i<3; i++)
{
get value food 1 and 2 and 3 here..

}


thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.