0

Hi,

I'm creating a table with X amount of rows (Importing from a Database table). I need to be able to click on a row in the table (any specified row), and onClick, the row number that was clicked on must be printed. Can anyone give me some advice on how to do this please?

Thanks a lot,
-Ashton.

4
Contributors
7
Replies
9
Views
8 Years
Discussion Span
Last Post by ChandraSekaranU
0

Where do you want to be printed?
I would suggest to have a button with each row that has that "onclick" event.
When the rows are dynamically created you can have the value you want to be printed passed as a parameter at a method in the "onclick" event.
I don't if you can just click the row. Check this site to see if the
<tr> tag has an "onclick" event:

Javascript
HTML

0

Hi,

I finally managed to find something. Here is the source:

<script type='text/javascript'>
            function getRow(t){
            alert(t.parentNode.rowIndex);
            //var row=t;
            //document.vSOForm.rowNumber.value = row;");
            }
            </script>

Then in the table, use it as follows:

<td onclick='getRow(this)'>

The problem I'm having now, however, is that I can't seem to pass the row number to a variable; and if I try to pass it to an input box using the lines that I commented out:

//var row=t;
//document.vSOForm.rowNumber.value = row;");

Then it places the string:
"[object]" into the input field.

If I use parseInt:

document.vSOForm.rowNumber.value = parseInt(row);

Then it places the string:
"NaN" into the input field.

Is there an alternative method of returning an integer value to the input field?

How about a way of sending the javascript row variable to a JSP Scriptlet variable?

Thanks again,
-Ashton.

0

Oops, nevermind, I fixed it!

<script type='text/javascript'>
            function getRow(t){
            alert(t.parentNode.rowIndex);
            //var row=t;
            //document.vSOForm.rowNumber.value = row;");
            }
            </script>

Should've been:

out.println("<script type='text/javascript'>");
            out.println("function getRow(t){");
            out.println("alert(t.parentNode.rowIndex);");
            out.println("var row=t.parentNode.rowIndex;");
            out.println("document.vSOForm.rowNumber.value = parseInt(row);");
            out.println("}");
            out.println("</script>");

Thanks anyway! Hope this thread helps someone else!

0

Well, I want to get select all rows from a specific database table to a JSP page. Then I want the JSP page to auto-generate an html table with all the data from the resultset. Once the data is displayed, I want to be able to click on any of the rows on the html table and get the value for the row number I clicked on so that I can reference an ArrayList of javabeans which contain each cell's data that will be sent to separate input fields that have Add/Update/Search functions, that require the text in the text input areas. Wow what a mouthful.

0

hi anyone tell me an idea how to insert multiple rows in to database.
Dynamically i add row and after adding rows i need to insert into database.I am using jsp and servlet .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.