Solved

find value of preceeding table cell

Posted on 2010-11-23
4
348 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

778 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