Solved

find value of preceeding table cell

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

679 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