Solved

get value by name

Posted on 2008-06-18
7
1,720 Views
Last Modified: 2012-06-21
how do i get value by name in jquery..
give example if u can ?
0
Comment
Question by:deepakabc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:shanikawm
ID: 21819823
if the element is

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

$(myinput).val() returns the value. No quotations.
0
 

Author Comment

by:deepakabc
ID: 21819860
inside form it's not working

i meanform tag
0
 
LVL 8

Expert Comment

by:shanikawm
ID: 21819895
Ahh..  Then,  $(form.element).val();

e.g.

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


$(myform.myinput).val() returns value.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:deepakabc
ID: 21819940
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
 
LVL 8

Expert Comment

by:shanikawm
ID: 21820328
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
 

Author Comment

by:deepakabc
ID: 21827347
<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
 
LVL 8

Accepted Solution

by:
shanikawm earned 500 total points
ID: 21828227
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question