Solved

get value by name

Posted on 2008-06-18
7
1,715 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now