473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how can i replace form values with text using jquery and php

index.php // php page

On my index.php i have many records... each record has a hidden form under it... for example...

Expand|Select|Wrap|Line Numbers
  1.  
  2. // record...
  3.  
  4. <li class="record"> 
  5.  
  6. <p class="first_name">Luke</p>
  7.  
  8. <h3 class="Last_name">Jordan</h3>
  9.  
  10. // form...
  11.  
  12. <form action="getName.php" method="post">
  13.  
  14. <input type="hidden" value="" name="firstName" id="firstName">
  15.  
  16. <input type="hidden" value="" name="lastName" id="lastName">
  17.  
  18. <input type="button" value="View full name" name="getFullName">
  19.  
  20. </form>
  21. </li>
  22.  
  23. // record...
  24.  
  25. <li class="record"> 
  26.  
  27. <p class="first_name">John</p>
  28.  
  29. <h3 class="Last_name">Smith</h3>
  30.  
  31. // form
  32.  
  33. <form action="getName.php" method="post">
  34.  
  35. <input type="hidden" value="" name="firstName" id="firstName">
  36.  
  37. <input type="hidden" value="" name="lastName" id="lastName">
  38.  
  39. <input type="button" value="View full name" name="getFullName">
  40.  
  41. </form>
  42. </li>
  43.  
  44.  
  45.  

myJquery.js // javascript/jquery page

I am trying to set the values in the forms to the names in the records above it, but with the code (jquery) that i have wrote... well it only seems to work for the first one.


Expand|Select|Wrap|Line Numbers
  1.  
  2.         var firstName = $(".first_name").html();
  3.         var lastName =  $(".Last_name").html();
  4.  
  5.  
  6.         $("#firstName").val(firstName);
  7.         $("#lastName").val(lastName);
  8.  
  9.  
All the records have the same classes as each other, and that cant be changed, i have been trying for ages now , please help me.
Mar 13 '11 #1

✓ answered by Sudaraka

You need to loop through each LI tag and assign values for each. Try this.
Expand|Select|Wrap|Line Numbers
  1. $('li.record').each(function(){
  2.  
  3.     $('#firstName', this).val($('.first_name', this).text());
  4.     $('#lastName', this).val($('.Last_name', this).text());
  5.  
  6. });
Also, please note that having same ID for multiple elements is not DOM complaint. consider using class instead.

1 1948
You need to loop through each LI tag and assign values for each. Try this.
Expand|Select|Wrap|Line Numbers
  1. $('li.record').each(function(){
  2.  
  3.     $('#firstName', this).val($('.first_name', this).text());
  4.     $('#lastName', this).val($('.Last_name', this).text());
  5.  
  6. });
Also, please note that having same ID for multiple elements is not DOM complaint. consider using class instead.
Mar 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Dave Karmens | last post by:
If I have say 10 fixed variables, how can I set their values = to that of a form that is built dynamically? column1 column2 email = formvalue(0) fname = formvalue(1) lname = formvalue(2)...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
1
by: JM | last post by:
Hello, Using Access 2000 queries, you can reference(pass) form values directly using syntax like Forms!frmPaint!txtColor. I want to do a pass through query to SQL Server 2000, but I don't know...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
2
by: darrel | last post by:
I'm still struggling to find a javascript/ajax library that I want to stick with for a while. JQuery is looking great these days...refined, LOTS of plug-ins, and an active community. Is...
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
10
rizwan6feb
by: rizwan6feb | last post by:
Hi I have created a tabbed interface using jQuery using the code below <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">...
4
by: pavanip | last post by:
Hi, I want to popup aspx page using jquery. I have written the following code <a href="Contactus.aspx?TB_iframe=true&height=250&width=200" class="thickbox" >AboutUs</a> I have called...
25
pradeepjain
by: pradeepjain | last post by:
<html> <head> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.rating.js" type="text/javascript" language="javascript"></script> <link...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.