This is my first on posting here. I hope you understand my question!
<script language="JavaScript">
function setVisibility(id, visibility)
{
document.getElementById(id).style.display = visibility;
}
</script>
<% for(cart c: cart) {%>
<td> ......</td>
<td> ......</td>
<td> ......</td>
<td> ......</td>
<td>
<input type=button name=type value='Edit' onclick="setVisibility('DivQTY', 'inline');">
<div id="DivQTY" style="display: none">
<input type="text" name="qty">
<form action="doEditCart.jsp?id=<%= c.getID() %>" method="post">
<input type="submit" value="Save">
</form>
</div>
</td>
<% }%>
This Shows a table and, in every row, shows a "Edit" button.
My problem here is that, if i press any "Edit" button in any row, "TextBox" and "Save" button appears only in the first row.
In this capture I pressed Edit in the fourth row.
How to show TextBox and Save button in the row that I pressed the edit button?
Thank you.
Your for statement is creating different <div> elements with the same id attribute, what is not allowed.
As a solution, you could use the cart's id (c.getID()) as part of the div's id:
(...)
<input type=button name=type value='Edit' onclick="setVisibility('DivQTY<%=c.getID()%>', 'inline');">
<div id="DivQTY<%=c.getID()%>" style="display: none">
(...)
The problem is at below line where you are using same id for each div
<div id="DivQTY" style="display: none">
Element IDs should be unique within the entire document. Use different dynamic IDs for each element in HTML.
HTML 4.01 specification says ID must be document-wide unique.
Read more about it here Two HTML elements with same id attribute: How bad is it really?
Related
I'm making a form to add events to a list but I need to be able to see in that form the previous events from that list. I have a jsp that shows a list of events but it takes an attribute usually added by the controller when you access the list directly from the browser.
So how can I add the list jsp filling that attribute so it shows a list and not just the headers?
I have alreay included the jsp using
<jsp:include page="comp_list.jsp"></jsp:include>
And it shows the headers but as there is no attribute it shows no list. I tried adding attributes to the include like:
<jsp:include page="comp_list.jsp">
<jsp:attribute name="compensaciones">
${compensaciones}
</jsp:attribute>
</jsp:include>
But when I do it it shows an error telling me that this cannot be done.
Also tried params but that would not be the answer for me because params are treated in the controller and not in the jsp itself.
I'm just getting the header of the list which is fine, but i would like to see the list.
Edit: this is how i build the list in case you are wondering
<tbody>
<c:forEach var="comp" items="${compensaciones}">
<td>${comp.getSomething()}</td>
...
</c:forEach>
</tbody>
<jsp:include page="pagename.jsp" />
i thing you are not provide extension in your include tag
Sometimes since I've had prior experience back in the days with HTML and PHP, we simply just would include things like navigation and header for easier management.
I'm unsure for what purpose you're including JSP, but here's an example of how I've done it since I include JSP if a boolean is true.
The site that is accessed:
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-8">
<%
if (loggedin) {
%>
<%# include file="includes/profile.jsp" %>
<% } else {
out.println("<div><h2>You aren't logged in!</h2></div>");
}
%>
</div>
<div class="col-lg-2">
</div>
</div>
And the top and bottom of the JSP file I'm including doesn't contain things like head, title, html, body etc.
<%
User currUser = null;
currUser = (User) session.getAttribute("user");
%>
<div>
<h2>Du er logget ind, velkommen <% out.println(currUser.getUsername().toUpperCase()); %></h2> <br>
<h5>Din Saldo: <b><% if (currUser.getBalance() < 0) { out.println("<font color='red'>" + currUser.getBalance() + "</font>");} else { out.println("<font color='green'>" + currUser.getBalance() + "</font>");} %></b></h5>
<br>
<form class="form" method="post" action="#">
<h4>Oplysninger: </h4>
<h6>
For at ændre oplysninger skal du indtaste dit kodeord!
</h6>
Nuværende Kode: <input type="password" class="form-control" placeholder="kodeord" name="password" required>
<hr>
Email: <input type="text" class="form-control" value="<% out.println(currUser.getEmail()); %>" name="email"> <br>
Brugernavn: <input type="text" class="form-control" value="<% out.println(currUser.getUsername()); %>" name="username"> <br>
<input type="submit" class="btn btn-default" value="Indsend Oplysninger" />
</form>
</div>
When importing JSP into JSP, it's important to know that they will conflict if 1. Duplicate Local Variables. 2. Certain HTML tags aren't correct.
Your intended use seems very complicated to me since I'm not quite understanding it, sorry :3 but if you can't get it working consider to throw it to a session and if it's a one time use then remove it once you used it.
This is working from dacades
<%# include file="../scripts/standard_head_declaration.jsp" %>
I'm working an OpenBravo application. I'm facing a problem with clicking an element when tried with a text id class. I'm able to find the element but the element is not clicking on that button.
I used the click() event with the action sendKeys() in JavaScript but it is still not working.
driver.findElement(By.id("terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton")).click();
Html format is
<div id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control">
<input style="width: 100%;margin-bottom:0px;background-color: #E8E8E8;width:300px" readonly="readonly" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EmployeeName" type="text" value="Kanika Sachdeva">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control2">
<input style="width: 100%;margin-bottom:0px;width:300px" maxlength="15" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EMPLOYEEID" placeholder="Enter Employee Id ..." type="text">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control3">
<button class="enyo-tool-decorator btnlink btnlink-gray modal-dialog-button" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton">OK</button>
</div>
I am using a Spring form with tabs, each tab again has a form.
The problems are
1)After the form submission, the error messages are displayed but the form content is cleared which should not happen
2)After the form submission the control immediately goes to the default tab which is the first tab in my case. I want the control to stay on current tab after transaction and not go to default tab.
This is the first time I am working using Spring MVC, JSP, jQuery. Please let me know if I have to make any changes.
administrator.jsp
Below is the code for Manage Users tab functionality.
jQuery:
$(document).ready(function() {
$('#btnManage').click(function() {
if($.trim($('#userId').val()) == ''){
$('#area5').html("User Id is a required field.");
}else if($.trim($('#region').val()) == 'NONE'){
$('#area5').html("Region is a required field.");
}else{
$('#manageUserForm').submit();
}
});
$('#btnCancel5').click(function(e) {
$('#manageUserForm').trigger("reset");
$('#area5').html("");
});
});
administrator.jsp:
<div id="tab5" class="tab">
<div class="devices" >
<form:form method="post" id="manageUserForm" modelAttribute="adminUser" action="/DeviceManager/admin/manageUser">
<div align=center class="message" id="area5">${serverError5}</div>
<div>
<div class="plLabelSearch">User Id:</div>
<div class="plinput"><form:input path="userId" type="text" size="29"/></div>
</div>
<div>
<div class="plLabelSearch">Region:</div>
<div class="plselect">
<form:select path="region">
<form:option value="NONE" label="------- Select One -------" />
<form:option value="A" label="A"/>
<form:options items="${regionList}"/>
</form:select>
</div>
</div>
<br>
<br>
<div>
<div class="plLabelSearch"> </div>
<div class="plinput"><a id="btnManage" class="abutton">OK</a></div>
<div class="plinput"><a id="btnCancel5" class="abutton">Cancel</a></div>
</div>
</form:form>
</div>
</div>
You need to re-render the page with the data from the original form submission.
In your case this probably means your form should contain a few hidden fields to allow you to determine which tab you are on, your JSP will need to be able to understand this data and use it to select the appropriate tab.
because you submission is not asynchronous,after you submit,the administrator.jsp is reset,so the error message is display ,owing to this code <div align=center class="message" id="area5">${serverError5}</div>
I have to show into a page the values of a matrix. Exactly I have a excel file mapped into matrix (ExcelField[][]) and the first row of this file is the label of the value of the below row (e.g. age heigh sex and th below row has the value 20 170 F).
Now I have to show the value near the label, three or four of this for any row of bootstrap page, like so:
The problem is the use of the matrix and the number of columns to show for any row. I think that it is impossible to use th:each as above image, it is possible to use for with variable as in java? Is there another way to make this?
Thanks
This is the code that I have written and tested, it works fine:
<div class="container">
<div th:each="j: ${#numbers.sequence(1, rowSize)}">
<div th:each="i: ${#numbers.sequence(0, colSize)}">
<div th:if="${i%3==0}">
<div class="row"></div>
</div>
<h3 th:if="${i==0 or i%3==0}">
<span class="label label-primary col-xs-1"
th:text="${excelSheet[0][i].value}"></span>
</h3>
<h3 th:if="${i!=0 and i%3!=0}">
<span class="label label-primary col-xs-1 col-xs-offset-1"
th:text="${excelSheet[0][i].value}"></span>
</h3>
<input class="km col-xs-2" name="distance" type="text"
th:value="${excelSheet[j][i].value}" />
</div>
</div>
</div>
I am trying to click on Button, but not able to click due to having same xpath's for all buttons on the webpage.
There are Questions with Yes and No option button. I want to identify the button with question.
All the Yes button are of same XPATH and all the No buttons are of same xpath.
Below is the HTML code to click on "Yes" button :
<div id="answerContainer_id" class="right two answerContainer">
<input id="validation_question_3_13" type="hidden" value="required"
name="validation_question_3_13"/>
<div class="answer questionAnsleft selected">
<input id="answer_3_13_1" type="radio" value="1" name="Q13" style="display:none;"/>
<div class="questionAnsRight">
Yes </div>
</div>
<div class="answer questionAnsleft disabled">
</div>
</div>
<div id="question_3_14" class="">
<input type="hidden" name="questionIds[]" value="14"/>
<div class="left" style="width: 680px;">
<div id="answerContainer_id" class="right two answerContainer">
<input id="validation_question_3_14" type="hidden" value="required"
name="validation_question_3_14"/>
<div class="answer questionAnsleft selected">
<input id="answer_3_14_1" type="radio" value="1" name="Q14" style="display:none;"/>
<div class="questionAnsRight">
Yes </div>
</div>
I dont even know how many questions are there in your page.. But as per your HTML source, there are two questions and two yes buttons. You can use the xpath as (xpath=//div[#class='questionAnsRight'])[1].
If you need to click more number of Yes buttons, iterate it with (xpath=//div[#class='questionAnsRight'])[i].
You can bind button to answer input
For first button css
#answer_3_13_1+div
For second
#answer_3_14_1+div
Or use name
[name=Q13]+div
[name=Q14]+div