Solved

get value by name

Posted on 2008-06-18
7
1,717 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
  • 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

773 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