Solved

get value by name

Posted on 2008-06-18
7
1,721 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

688 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