Put selected cell value into textbox

Hello!
I have

  1. Database with columns “Group”, “Num”, “Name”, “Abbr”. It was linked with a table (similar titles for cols). It has some rows of data
  2. Button for filling in the textbox
  3. Textbox

I want to do that:

  1. When I click button, the value of “Abbr” column from selected row is appears in the textbox below.
  2. When I click second time, the next value is appears at the next line.

I tried add code to onRowSelect, onCellSelect, onButtonClick, but cannot get selected row index. My cellRowIndex var is outside to be a global.
Now my code as follows:

let cellRowIndex;

export function button1_click(event, $w) {
	//Add your code for this event here: 
	let tableRows = $w("#table1").rows;
	console.log(tableRows); 
	let value = tableRows[cellRowIndex]["abbr"]; // "field value"
	console.log(value);
	$w("#textBox2").value = value;
}

export function table1_cellSelect(event, $w) {
	//Add your code for this event here: 
  $w("#table1").onCellSelect( (event, $w) => {
  		cellRowIndex = event.cellRowIndex;  // 1
  		console.log(event);
	} );
}

It shows all the data in console, but then writes:
TypeError: Cannot read property ‘abbr’ of undefined

Sorry for my English. How can I get selected row index?

Hi Lana,

You state that you have a column Abbr , so the line of code be:
let value = tableRows[cellRowIndex][“Abbr”]; // “field value”

The name of the column is Abbr - however abbr is undefined.

I hope this helps,

Yisrael

Hello, Yisrael! Thanks for your answer, unfortunately, it did not help, it types “Error” at any case:

TypeError: Cannot read property ‘abbr’ of undefined
or
TypeError: Cannot read property ‘Abbr’ of undefined

I’ll better show all the log:

Onload:

[Violation] 'setTimeout' handler took 110ms
contentscript.js:54 <body class=​"warmup" data-js-loaded=​"true" style>​…​</body>​
require.min.js:29 [Violation] 'load' handler took 244ms

contentscript.js:54 <body>​OK​</body>​

core.min.js:1 [Violation] 'setTimeout' handler took 51ms

44[Violation] Added non-passive event listener to a scroll-blocking <some> event. Consider marking event handler as 'passive' to make the page more responsive. See <URL>

core.min.js:1 [Violation] 'setTimeout' handler took 681ms

console.js:35 Loading the code for the Add patient page. To debug this code, open wbune.js in Developer Tools.
platformInit.min.js:1 [Violation] 'message' handler took 347ms
animations.min.js:1 [Violation] 'requestAnimationFrame' handler took 50ms

After button click:

my data (also logged in console for debug), it’s ok:


(15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
 

Here’s one of the items:

0:
abbr:"ALT"
group:"hep"
name:"ALT"
num:9

and errors:


TypeError: Cannot read property 'Abbr' of undefined
    at Object.button1_click (wbune.js:26)
    at Object.f [as onMessage] (eval at importScripts (scriptHandler.js:38), <anonymous>:1:33740)
    at Object.l [as onMessage] (eval at importScripts (scriptHandler.js:38), <anonymous>:1:128494)
    at worker.js:139
    at j (worker.js:132)

Uncaught TypeError: Cannot read property 'Abbr' of undefined
    at Object.button1_click (wbune.js:26)
    at Object.f [as onMessage] (eval at importScripts (scriptHandler.js:38), <anonymous>:1:33740)
    at Object.l [as onMessage] (eval at importScripts (scriptHandler.js:38), <anonymous>:1:128494)
    at worker.js:139
    at j (worker.js:132)

It seems, that my code can’t get existing value, due to its access or something else.
Database is open for reading/writing/editing for site members, and I’m admin.

Please post the URL of your site and I’ll take a look. Only authorized Wix personnel can get access to your site in the editor.

Sorry for long answer, https://light1force.wixsite.com/doct/members-id

Hi Lana,

I looked on all of the pages of your site and I don’t see the code that you posted above.

Also, the database collections are empty, so if you ran that code, it would certainly result in undefined since nothing would be returned.

Yisrael

Hello Yisrael!
Thanks for all, but I filled the db, and it appears on the screen as table with data. I’ll think about changing the function to simplify it.

Hi Lana,

I looked in your Sandbox database and the collections are all empty. This means when you run Preview from the Editor nothing will happen since you have no data.

Yisrael

Hi @yisrael-wix , Could you please check pollywoodcafe.com . Getting similar voilation error. In preview custom login works & redirect to blog page while in live it doesn’t do nothing.

This is an old post and is being closed.
Please add your own issue into a new post instead of bumping up an old post.
Also, please explain what’s working, what’s not, and show us the relevant code in a code block as stated in the Forum Guidelines.