cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript validation for dropdown value in the table view

Former Member
0 Kudos

I have a dropdown listbox in a table view (I’m using iterator). I’d like to do a client side validation when the user select one of the value in the dropdown box.

Here is my code in the class iterator:

WHEN 'PERNO'.

DATA dropdownbox TYPE REF TO cl_htmlb_dropdownlistbox.

CREATE OBJECT dropdownbox.

dropdownbox->id = p_cell_id.

GET REFERENCE OF me->z_crew_list INTO dropdownbox->table.

dropdownbox->nameofkeycolumn = 'Name'.

dropdownbox->nameofvaluecolumn = 'Value'.

dropdownbox->selection = get_column_value( 'PERNO' ).

dropdownbox->onClientSelect = 'employeeCheck()'.

dropdownbox->width = 'auto'.

p_replacement_bee = dropdownbox.

I would like to get the selected employee number and validate in the employeeCheck().

How do I get the value of the selected PERNO? Can I use document.getElementById.value?

Thanks,

Maria

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Maria,

Your code is correct. If your tableview has 5 rows, there would 5 such dropdowns. You should pass employeeCheck function the p_cell_id also, so that the function understands which dropdown is currently being operated.

<b>data: l_jsfunc type string.</b>

WHEN 'PERNO'.

DATA dropdownbox TYPE REF TO cl_htmlb_dropdownlistbox.

CREATE OBJECT dropdownbox.

dropdownbox->id = p_cell_id.

GET REFERENCE OF me->z_crew_list INTO dropdownbox->table.

dropdownbox->nameofkeycolumn = 'Name'.

dropdownbox->nameofvaluecolumn = 'Value'.

dropdownbox->selection = get_column_value( 'PERNO' ).

<b>concatenate 'employeeCheck("'

p_cell_id

'")'

into l_jsfunc.

dropdownbox->onClientSelect = l_jsfunc.</b>

*dropdownbox->onClientSelect = 'employeeCheck()'.

dropdownbox->width = 'auto'.

p_replacement_bee = dropdownbox.

If you facing any problems using getElementByID , then use

document.form1(p_cellid).value ...

Regards,

Alwyn

Former Member
0 Kudos

Thank you Alwyn for your prompt response. Now, I am able to get the value of the cell.

I have another question, is there a way to get the previous value of the cell?

E.g: When I run the page, the cell contains '12345'. Then I select another value '00000' (from the dropdown list) which will triger onClientClick event. This value is not valid, so I give an alert: 'This value is not valid', and the value of the cell suppose to go back to '12345'.

How do I get the value '12345' back?

Thanks,

Maria

Former Member
0 Kudos

Hi Maria,

Change your function as below

< script >

var lastselectedindex = new Array();

function func(obj)

{ var sels = document.getElementsByTagName("select");

var sel = document.form1(obj).

var i;

var sel_num_in_doc = 0;

for ( i = 0; i < sels.length; i++ )

{ if (sel == sels<i>)

{ sel_num_in_doc = i;

}

}

if ( not matching )

{

sel.selectedIndex = lastselectedindex[sel_num_in_doc];

}

else

{

lastselectedindex[sel_num_in_doc] = sel.selectedIndex;

}

return true;

}

< /script >

Regards,

Alwyn

Answers (0)