Solved

find value of preceeding table cell

Posted on 2010-11-23
4
343 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
Comment Utility

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-
Comment Utility
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
Comment Utility
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-
Comment Utility
Worked out solution
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now