Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

find value of preceeding table cell

Posted on 2010-11-23
4
Medium Priority
?
363 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-
[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
4 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 800 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

715 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