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
Solved

find value of preceeding table cell

Posted on 2010-11-23
4
351 Views
Last Modified: 2012-05-10
Hi,

I'm using this program http://code.google.com/p/jquery-in-place-editor/ and what I would like to do is get the reference from a preceding cell in a table into a parameter it passes.

a table line is formatted like this:

<tr class="datatab">
                  <td>WJEC Level 3 Advanced GCE in Art and Design</td>
                  <td>50026094</td>
                  <td>GCE</td>
                  <td>Aug 2014</td>
                  <td>80</td>
                  <td>G</td>
                  <td>D</td>
                  <td>Live</td>
                  <td>3</td>
                  <td>Y</td>
                  <td><div id="50026094" class="fillme">2</div></td>
                  <td class="pw">2</td>
                  <td>4354</td>
</tr>

and my code is targeting the second to last cell.

when this cell id is modified I would like to pass the second cells value as a parameter

so something like:

          $(".pw").editInPlace({

              url: "capture.php",
                params:"ref={2nd cell Value of this line}"
          });

how can I get the value into {2nd cell Value of this line}  ie 50026094 using JQuery?
0
Comment
Question by:darren-w-
  • 3
4 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 200 total points
ID: 34195834

There's probably a better way but hover on a cell to get the previous entry:

<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26633355.html</title>

<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

<script>

$(document).ready(function()
{

  $("td").mouseover(function(caller){

    var i = 0;

    while ( caller.fromElement.cells[i++] != caller.srcElement );

    i = (i == 1)? 0 : i - 2;

    alert( caller.fromElement.cells[i].innerText );

  });
});

</script>


</head>
<body>

<table border="1">
  <tr class="datatab">
    <td>WJEC Level 3 Advanced GCE in Art and Design</td>
    <td>50026094</td>
    <td>GCE</td>
    <td>Aug 2014</td>
    <td>80</td>
    <td>G</td>
    <td>D</td>
    <td>Live</td>
    <td>3</td>
    <td>Y</td>
    <td><div id="50026094" class="fillme">2</div></td>
    <td class="pw">2</td>
    <td>4354</td>
  </tr>
<table>

</body>
</html>

Open in new window

0
 
LVL 13

Author Comment

by:darren-w-
ID: 34196066
I've managed to get round it like this

       $('tr.datatab td:nth-child(2)').addClass('ref');
            $('tr.datatab td:nth-child(12)').each(function(){
                var ref = $(this).siblings(('.ref')).text();
                $(this).attr('id','ref:'+ref);
                $(this).addClass('pw');

            });
          $(".pw").editInPlace({
              url: "capture.php"
               
          });
            });

I split out the ref in php
0
 
LVL 13

Assisted Solution

by:darren-w-
darren-w- earned 0 total points
ID: 34239319
This is my most recent solution (added a select list):

$('tr.datatab td:nth-child(12)').each(function(){
                    var ref = $(this).siblings(('.ref')).text();
                    $(this).attr('id','ref:'+ref);
                    $(this).addClass('pw');

                });

//attached eip

                $(".pw").each(function(){
                    $(this).editInPlace({
                        url: "capture.php",
                        field_type:"select",
                        params:"<?php echo $params; ?>",
                        select_options:getval(this),
                        select_text:"",
                        bg_over:""
                    });
                });

//build pulldown
                function getval(val){
                    var rtn="";
                    var top= $(val).prev().text();
                    for (i=0;i<=top;i++)
                    {
                        rtn=rtn+i;
                        if (i!=top){
                            rtn=rtn+",";
                        }
                    }
                    return rtn
                }

Open in new window

0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 34276702
Worked out solution
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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…
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…

861 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