Get a particular cell value from HTML table using JavaScript

前端 未结 10 836
暖寄归人
暖寄归人 2020-12-15 06:09

I want to get each cell value from an HTML table using JavaScript when pressing submit button.

How to get HTML table cell values?

10条回答
  •  时光说笑
    2020-12-15 06:14

    You can get cell value with JS even when click on the cell:

    .......................
    
          
    
            Search students by courses/professors
    
            
    
        
        
    
             
    
                    <% for (Course cs : courses){ %>
    
                    
                   <%}%>
    
        ........................
        

    I wrote the HTML table in JSP. Course is is a type. For example Course cs, cs= object of type Course which had 2 attributes: id, title. courses is an ArrayList of Course objects.

    The HTML table displays all the courses titles in each cell. So the table has 1 column only: Course1 Course2 Course3 ...... Taking aside:

    onclick="DoNav('http://localhost:8080/Mydata/ComplexSearch/FoundS.jsp?courseId=<%=cs.getCourseId()%>');"
    

    This means that after user selects a table cell, for example "Course2", the title of the course- "Course2" will travel to the page where the URL is directing the user: http://localhost:8080/Mydata/ComplexSearch/FoundS.jsp . "Course2" will arrive in FoundS.jsp page. The identifier of "Course2" is courseId. To declare the variable courseId, in which CourseX will be kept, you put a "?" after the URL and next to it the identifier.

    I told you just in case you'll want to use it because I searched a lot for it and I found questions like mine. But now I found out from teacher so I post where people asked.

    The example is working.I've seen.

    提交回复
    热议问题
    <%= cs.getTitle() %>