Solved

how to get the value in a table to be in a field on a form with jquery

Posted on 2011-03-07
6
304 Views
Last Modified: 2012-05-11
Hi.
I have a form that I'm that I'm trying to get dat into the fields from a table on the page. the info in the table changes when a dropdown is selected.  I'm trying to retreive some of the data in the columns and place it in a form on the page with jquery.  I'm having a bit of trouble. Can anyone help??
 Below is the table that I'm trying to catch the data from....
<!--<table TOPLEVEL border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td valign="top">
		<div >
		<table>
		<tr valign="top">
		<th class="ms-vh" nowrap>app</th>
		<th class="ms-vh" nowrap id="appData">business owner</th>
		<th class="ms-vh" nowrap>Busness Owner2</th>
		</tr>
		<tr class="ms-alternating">
		
		<td class="ms-vb">ab</td>
		
		<td class="ms-vb">
		    <nobr>
		    <span>
		    <A HREF="">Business Owner Value</A>
		    </span>
		    </nobr>
		</td>
		
		<td class="ms-vb">
		    <nobr>
		    <span>
		    <A HREF="">Business Owner 2 Value</A>
		    </span>
		    </nobr>
		</td>
		</tr>
</table>

Open in new window

0
Comment
Question by:InvAutomation
[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
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 35059330
I see your table, and you can get data with selectors like
$("table tr")(1).find("td")

But without knowing what you are specifically trying to get and how it changes, it is hard to give a specific answer.  I know I'd probably at least add an id to the table you are interested in to make the selector easier to work with.
0
 

Author Comment

by:InvAutomation
ID: 35059501
Sorry about that!

I'm trying to get the values in these rows:

            <td class="ms-vb">ab</td>
            
            <td class="ms-vb">
                <nobr>
                <span>
                <A HREF="">Business Owner Value</A>
                </span>
                </nobr>
            </td>
            
            <td class="ms-vb">
                <nobr>
                <span>
                <A HREF="">Business Owner 2 Value</A>
                </span>
                </nobr>
            </td>


Then I'm trying to put those values in
<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff1_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff1_1_ctl00_ctl00_TextField" title="Title" class="ms-long" />

<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff2_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff2_1_ctl00_ctl00_TextField" title="business owner" class="ms-long" />

<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff3_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff3_1_ctl00_ctl00_TextField" title="Business Owner 2" class="ms-long" />

Open in new window

0
 
LVL 15

Expert Comment

by:SRigney
ID: 35059604
Based on what I can see in your html
$("td.ms-vb") will return the 3 columns you are interested in.

var data = $("td.ms-vb")
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff1_1_ctl00_ctl00_TextField").val(data(0).html());

// get the html inside of the a that is in the 2nd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff2_1_ctl00_ctl00_TextField").val(data(1).find("a").html());

// get the html inside of the a that is in the 3rd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff3_1_ctl00_ctl00_TextField").val(data(2).find("a").html());
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:InvAutomation
ID: 35059812
HMM,,,

That didn't work.

I tried       <script>      

            var data = $("td.ms-vb")
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff1_1_ctl00_ctl00_TextField").val(data(0).html());

// get the html inside of the a that is in the 2nd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff2_1_ctl00_ctl00_TextField").val(data(1).find("a").html());

// get the html inside of the a that is in the 3rd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff3_1_ctl00_ctl00_TextField").val(data(2).find("a").html());

</script>



and


      <script>      
$(document).ready(function(){

            var data = $("td.ms-vb")
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff1_1_ctl00_ctl00_TextField").val(data(0).html());

// get the html inside of the a that is in the 2nd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff2_1_ctl00_ctl00_TextField").val(data(1).find("a").html());

// get the html inside of the a that is in the 3rd column with a class of ms-vb, put it into the value of the input with this id.
$("#ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff3_1_ctl00_ctl00_TextField").val(data(2).find("a").html());
});
</script>
0
 
LVL 15

Expert Comment

by:SRigney
ID: 35064022
The best way to debug this is with FireBug in Firefox, or the developer tools in IE8 or Google Chrome.  You can set a breakpoint on the javascript and see what is specifically happening.

I made the assumption that this one row of 3 columns is the only thing that has the class .ms-vb on it.  In the developer tools you can verify how many items $("td.ms-vb") is returning.  You can also verify that each of the other statements is finding the item that you intend it to.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35076467
Check this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">

	$(document).ready(function() {
//		$("td.ms-vb", "table").each(function() { // if you have only one table in your doc
		$("td.ms-vb", "#tableid").each(function(i) {
			var $obj = ($(this).find("a").length>0)?$(this).find("a"):$(this);
			$("input[name^='ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$']:eq(" + i + ")").val( $obj.text() );
		});
	});

</script>
</head>
<body>
<table id="tableid" border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td valign="top">
		<div >
		<table>
		<tr valign="top">
		<th class="ms-vh" nowrap>app</th>
		<th class="ms-vh" nowrap id="appData">business owner</th>
		<th class="ms-vh" nowrap>Busness Owner2</th>
		</tr>
		<tr class="ms-alternating">
		
		<td class="ms-vb">ab</td>
		
		<td class="ms-vb">
		    <nobr>
		    <span>
		    <A HREF="">Business Owner Value</A>
		    </span>
		    </nobr>
		</td>
		
		<td class="ms-vb">
		    <nobr>
		    <span>
		    <A HREF="">Business Owner 2 Value</A>
		    </span>
		    </nobr>
		</td>
		</tr>
</table>
<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff1_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff1_1_ctl00_ctl00_TextField" title="Title" class="ms-long" />

<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff2_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff2_1_ctl00_ctl00_TextField" title="business owner" class="ms-long" />

<input name="ctl00$PlaceHolderMain$g_0ea84a0f_dc84_4456_8f01_af9045c280fd$ff3_1$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_PlaceHolderMain_g_0ea84a0f_dc84_4456_8f01_af9045c280fd_ff3_1_ctl00_ctl00_TextField" title="Business Owner 2" class="ms-long" />
</body>
</html>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
arrays and buttons with user input 2 41
Aspx calendar pop up control 3 36
Looking for solution to pass data to 3rd-party web platform? 4 56
javascript delete path 7 42
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

738 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