Get value of display:column property JSP page in JS

39 Views Asked by At

I don't know how to get the value of a display:column in a JSP page to check in a JS function.

JSP Page:

<display:table>
...

<display:column property="surnameName" title="Surname, Name" />
<display:column property="type" title="Type"/>
....
</display:table>

JS function:

function next2(){
...
var type = $('.type').val(); //Obtain an undefined value
...
if (documents.length > 1 && (type=='Mail Addresss' || type=='Ordinary')) {

        alert("You must select at least a PDF for Mail Addresss or Ordinary type for the stakeholder");

        return false;

    }
...
}
1

There are 1 best solutions below

1
Lalit Kumar On
function next2() {
var types = []; 


$('.your-table-selector').find('tr').each(function() {
    
    var type = $(this).find('td:eq(1)').text().trim(); // Assuming type is in the second column (index 1)

    
    types.push(type);
});

if (types.length > 1 && (types.includes('Mail Addresss') || types.includes('Ordinary'))) {
    alert("You must select at least a PDF for Mail Addresss or Ordinary type for the stakeholder");
    return false;
}}

Replace '.your-table-selector' with the appropriate selector for your table. This code assumes that the type values are displayed in the second column of your table. Adjust the index in td:eq() if the column position is different.

This JavaScript function will extract all the type values from the displayed table rows and perform the necessary validation based on the conditions you've specified.