I created a dynamic table after receiving with hashmap. Previously I used json as input and javascript and I was able to pre-select radio buttons based on json input. However below code is not working neither for pre-selecting and when selecting the radio button only of all the radio buttons is being selected.
Please help, I am new to jsp and hashmap so pardon any syntax errors.
<tr align="left">
<td align="left"> <%out.println( tempsysDetails1.getCategory().get(i)); %> </td>
<td align="left"> <input type="radio" name="inlineRadioOptions_' + i + '[]" value="0" id="inlineRadio0"' +
(tempsysDetails1.getSystemStatus().get(i)) = 0 ? ' checked="checked"' : '' ) + '><font color="black">Grey </font><label class="radio-inline">
<input type="radio" name="inlineRadioOptions_' + i + '[]" value="1" id="inlineRadio1"' + tempsysDetails1.getSystemStatus().get(i)) = 1 ? ' checked="checked"' : '') +
'><font color="green">Green </font><label class="radio-inline"><input type="radio" name="inlineRadioOptions_' + i + '[]" + id="inlineRadio2" value="2"' +
(tempsysDetails1.getSystemStatus().get(i)) = 2 ? ' checked="checked"' : '' ) + '><font color="yellow">Yellow </font></label><label class="radio-inline">
<input type="radio" name="inlineRadioOptions_' + i + '[]" id="inlineRadio3" value="3"' +
(tempsysDetails1.getSystemStatus().get(i)) = 3 ? ' checked="checked"' : '') + '> <font color="red">Red</font></label></td>
<td align="left"><input type="text" id= "comments[i]" class="form-control name_list" placeholder="<%out.println( tempsysDetails1.getComments().get(i)); %> "> </td>
</tr>
Attaching screenshot for reference:
Related
I am working on a personal project and wants to parse this html and retrieve information from this.
Basically I want to get all the information that is given inside the 'br' tags ,for this I am using JSOUP in java .
I want to store these value as pairs in a map (key,value).
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style> </style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="">
<div class="WordSection1">
<p class="MsoNormal">
<span style=""></span>
</p>
<p class="MsoNormal">
<span style=""></span>
</p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="MsoNormal">
<a name="_MailOriginal">
<b>
<span style="">From: </span>
</b>
</a>
<span style="">
<span style=""> ABC (membership#abc.org)
<br>
<b>Sent: </b> Tuesday, November 24, 2020 8:13 AM <br>
<b>To: </b> XYZ <XYZ#abc.com>
<br>
<b>Subject: </b> Information Request </span>
</span>
</p>
</div>
</div>
<p class="MsoNormal">
<span style=""></span>
</p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left" width="100%" style="width:100.0%">
<tbody>
<tr style="">
<td style="background:#910A19; padding:5.25pt 1.5pt 5.25pt 1.5pt">
<span style=""></span>
</td>
<span style=""></span>
<td width="100%">
<div>
<p class="MsoNormal" style="">
<span style="">
<b>
<span style="font-size:12.0pt; font-family:" ` Calibri (Body)`",serif; color:#212121">EXTERNAL EMAIL: Beware of Phishing attacks! </span>
</b>
</span>
</p>
</div>
</td>
<span style=""></span>
</tr>
</tbody>
</table>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%; background:#B2B2B2">
<tbody>
<tr style="">
<td style="padding:25.0pt 25.0pt 25.0pt 25.0pt">
<div align="center">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="600" style="width:6.25in; background:white; border:solid black 1.0pt">
<tbody>
<tr style="">
<td style="border:none; padding:2.0pt 2.0pt 2.0pt 2.0pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="">
<tbody>
<tr style="">
<td style="border:none; border-bottom:solid #CDCDCD 1.0pt; padding:7.5pt 3.75pt 7.5pt 3.75pt">
<p class="MsoNormal">
<span style="">
<span style="border:solid windowtext 1.0pt; padding:0in">
<img width="100" height="100" id="_x0000_i1025" src="cid:~WRD2635.jpg" alt="Image removed by sender.">
</span>
</span>
<span style="">
<span style=""></span>
</span>
</p>
</td>
<span style=""></span>
<td width="100%" style="width:100.0%; border:none; border-bottom:solid #CDCDCD 1.0pt; padding:7.5pt 3.75pt 7.5pt 3.75pt">
<p class="MsoNormal">
<span style="">
<b>
<span style="font-size:18.0pt; font-family:" Arial",sans-serif">AWSCV </span>
</b>
</span>
</p>
</td>
<span style=""></span>
</tr>
</tbody>
</table>
<span style=""></span>
</td>
<span style=""></span>
</tr>
<tr style="">
<td style="border:none; padding:2.0pt 2.0pt 2.0pt 2.0pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="">
<tbody>
<tr style="">
<td style="border:none; border-bottom:solid #CDCDCD 1.0pt; padding:7.5pt 7.5pt 7.5pt 7.5pt">
<p class="MsoNormal">
<span style="">
<span style="font-size:9.0pt; font-family:" Arial",sans-serif">Dear XYZ, <br>
<br>The following Information Request form was submitted by ABC, Company: asd, Email: asd#abc.com on 11/23/2020. <br>
<br>Information: <br>
<br>Legal Business Name <br>Asfdsf <br>
<br>Phone <br>(718) 43543 <br>
<br>Principle Name 1 <br>afdsgsfgsg df <br>
<br>EIN <br>04543 <br>
<br>Bus Street Address <br>fdgfdgfdg <br>
<br>Bus City <br>fgfdvgdsgs <br>
<br>Bus State <br>dsf <br>
<br>Bus Zip Code <br>34543534 <br>
<br>Email Address <br>abc#gamil.com <br>
<br>Secondary Email Address <br>abc#gamil.com <br>
<br>Business Website Address <br>NOEMAIL.COM <br>
<br>DBA info same as Business <br>
<br>DBA information is same as Business. <br>
<br>DBA Name <br>Asfdsf <br>
<br>DBA Street Address <br>sgfdgfdg435435 34 <br>
<br>DBA City <br>ACDCROCK <br>
<br>DBA State <br>AT <br>
<br>DBA Zip Code <br>324324 <br>
<br>DBA Phone <br>(458) 43543543 <br>
<br>DBA Email Address <br>abc#gamil.com <br><br>Secondary DBA Email Address <br>--- No answer --- <br><br>Tertiary DBA Email Address <br>--- No answer --- <br><br>DBA Website Address <br>NOEMAIL.COM <br><br>Secondary DBA Website Address <br>--- No answer --- <br><br>Tertiary DBA Website Address <br>--- No answer --- <br><br>Information Request Text <br>Any information would be helpful <br><br> Description <br>ACCESSORIES <br><br>wegf <br>4545 <br><br>Point of Sale Type <br>dfgfdg/sdgfdsgdsg (Default) <br><br><br><br>Attachments: </span></span>
</p><table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="600" style="width:6.25in; background:white; border:outset black 1.0pt"><tbody><tr style=""><td style="padding:2.0pt 2.0pt 2.0pt 2.0pt"><p class="MsoNormal"><span style=""><span style="color:black">Attachments </span></span><span style=""><span style=""></span></span></p></td><span style=""></span><td style="padding:2.0pt 2.0pt 2.0pt 2.0pt"><p class="MsoNormal"><span style=""><span style="color:black"></span></span><span style=""><span style=""></span></span></p></td><span style=""></span></tr></tbody></table><p class="MsoNormal"><span style=""><span style="font-size:9.0pt; font-family:" Arial",sans-serif"><br><br>Your type includes you in the list of members to whom forms of this type are sent. You can opt out of receiving forms of this type via the Forms link on your Profile screen. </span></span></p>
</td><span style=""></span>
</tr>
</tbody>
</table><span style=""></span>
</td><span style=""></span>
</tr><tr style=""><td style="border:none; padding:2.0pt 2.0pt 2.0pt 2.0pt"><div><p class="MsoNormal"><span style=""><i><span style="font-size:7.5pt; color:#666666">This email was sent in response to the use of the platform and website by AWCC. It was generated by: </span></i></span></p><div style="margin-left:11.25pt; margin-top:3.0pt"><p class="MsoNormal"><span style=""><i><span style="font-size:7.5pt; color:#666666">AAXC, LLC <br>43543543 fgfdgfdg <br>AXD, WE 324324 <br>dgfdgfdgfd (457-dsfds) - Outside the US, call +1 45435435435 </span></i></span></p></div></div></td><span style=""></span></tr>
</tbody>
</table>
</div><span style=""></span>
</td><span style=""></span>
</tr>
</tbody>
</table><span style=""></span><p class="MsoNormal"><span style=""></span></p>
</div>
</body>
</html>
I am using this code to fetch but this is giving all values in a paragraph.
Document doc = Jsoup.parse(htmlString);
List<String> valueList = new ArrayList<>();
Elements keyElements = doc.getElementsByTag("td");
for (Element keyElement : keyElements) {
String value = keyElement.text();
// store in value list
}
I also tried
doc.getElementsByTag("br");
but his is giving empty value.
I want to store each the values in a map like this but not able to separate the value from html as this is coming in paragraph or empty.
My Map ..
Key VALUE
Phone (718) 3543
Legal Business Name Asfdsf
DBA City XYXXdsfds
... and so on
Can someone please help me to get this data in a better way?
it must be getElementsByTagName . T.T
You can use this solution:
Document.OutputSettings outputSettings = new Document.OutputSettings();
outputSettings.prettyPrint(false);
doc.outputSettings(outputSettings);
doc.select("br").before("\\n");;
doc.select("p").before("\\n");
String str = doc.html().replaceAll("\\\\n", "\n");
String strWithNewLines = Jsoup.clean(str, "", Safelist.none(), outputSettings);
System.out.println(strWithNewLines);
I suppose you can try this:
If the HTML String was this:
String html = "<html>\n"
+ " </head>\n"
+ "<table class=\"MsoNormalTable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"\">\n"
+ " <tbody>\n"
+ " <tr style=\"\">\n"
+ " <td>\n"
+ " <p class=\"MsoNormal\">\n"
+ " <span style=\"\">\n"
+ " <span style=\"font-size:9.0pt; font-family:\"Arial\",sans-serif\">\n"
+ " <br>\n"
+ " <br>Information: \n"
+ " <br>\n"
+ " <br>Legal Business Name\n"
+ " <br>Asfdsf\n"
+ " <br>\n"
+ " <br>Phone\n"
+ " <br>(718) 43543\n"
+ " <br>\n"
+ " <br>Principle Name 1\n"
+ " <br>afdsgsfgsg df\n"
+ " <br>\n"
+ " <br>Bus Street Address\n"
+ " <br>sdfdsf\n"
+ " <br>\n"
+ " <br>Bus City\n"
+ " <br>sdfdsf\n"
+ " <br>\n"
+ " <br>Bus State\n"
+ " <br>ny\n"
+ " <br>\n"
+ " <br>Bus Zip Code\n"
+ " <br>4324324\n"
+ " <br>\n"
+ " <br>Email Address\n"
+ " <br>dsfdsfds#xyz.com\n"
+ " <br>\n"
+ " <br>Tertiary Email Address\n"
+ " <br>--- No answer ---\n"
+ " <br>\n"
+ " <br>Business Website Address\n"
+ " <br>dsfdsf.com\n"
+ " <br>\n"
+ " <br>DBA info same as Business\n"
+ " <br>\n"
+ " <br>DBA information is same as Business.\n"
+ " <br>\n"
+ " <br>DBA Name\n"
+ " <br>Awqeewd gdfg\n"
+ " <br>\n"
+ " <br>DBA Street Address\n"
+ " <br>dsfdsf 3432 fdgdf\n"
+ " <br>\n"
+ " <br>DBA City\n"
+ " <br>NORTH\n"
+ " <br>\n"
+ " <br>Attachments:\n"
+ " </span>\n"
+ " </span>\n"
+ " </p>\n"
+ " <p class=\"MsoNormal\">\n"
+ " <span style=\"\"> \n"
+ " </span>\n"
+ " </p>\n"
+ " </div>\n"
+ " </body>\n"
+ " </html>";
And you run this string through the following method provided below:
String[] values = getTextAfterHtmlStartEndTags(html, "br");
// Display the discovered values...
for (String str : values) {
System.out.println(str);
}
The console Window will display:
Information:
Legal Business Name
Asfdsf
Phone
(718) 43543
Principle Name 1
afdsgsfgsg df
Bus Street Address
sdfdsf
Bus City
sdfdsf
Bus State
ny
Bus Zip Code
4324324
Email Address
dsfdsfds#xyz.com
Tertiary Email Address
--- No answer ---
Business Website Address
dsfdsf.com
DBA info same as Business
DBA information is same as Business.
DBA Name
Awqeewd gdfg
DBA Street Address
dsfdsf 3432 fdgdf
DBA City
NORTH
Attachments:
The getTextAfterHtmlStartEndTags() method:
/**
*
* To be used with the JSoup API<br><br>
* <b>Example Usage:</b><br><pre>
*
* <b>Required Imports:</b>
*
* import org.jsoup.Jsoup;
* import org.jsoup.nodes.Document;
* import org.jsoup.nodes.Element;
* import org.jsoup.nodes.Node;
* import org.jsoup.select.Elements;
*
* <b>Example Code:</b>
*
* {#code String html = "<td>\n"
* + " <span class=\"detailh2\" style=\"margin:0px\">This month: </span>2 145 \n"
* + " <span class=\"detailh2\">Total: </span> 31 704 \n"
* + " <span class=\"detailh2\">Last: </span> 30.12.2021 \n"
* + "</td>";
*
* String[] values = getTextAfterHtmlStartEndTags(html, "span");
* for (String str : values) {
* System.out.println(str);
* }}</pre><br>
* <p>
* The console window will display:
* <pre>
*
* 2 145
* 31 704
* 30.12.2021</pre><br>
* <p>
* If you want the data from a specific HTML tag element then you can supply
* one or more text elements within those HTML tags in th optional
* 'specificTo' parameter as a string array or as args, for example:
* <pre>
*
* {#code String[] values = getTextAfterHtmlStartEndTags(html, "span", "This month:", "Total:");
* for (String str : values) {
* System.out.println(str);
* }}</pre><br>
* <p>
* The console window will display:
* <pre>
*
* This month: --> 2 145
* Total: --> 31 704</pre>
*
* #param htmlString (String) The HTML string to parse.<br>
*
* #param htmlStartTagString (String) The HTML start tag to get data
* from.<br>
*
* #param specificTo (String - args) The desired data from multiple
* HTML tags of the same type (see the above
* example code).<br>
*
* #return (String[] Array) A single Dimensional String Array containing the
* desired data (if properly parsed and found).
*/
public static String[] getTextAfterHtmlStartEndTags(String htmlString,
String htmlStartTagString, String... specificTo) {
String html = htmlString;
List<String> list = new ArrayList<>();
String value = "N/A";
Document doc = Jsoup.parse(html);
Elements elements = doc.select(htmlStartTagString);
for (Element a : elements) {
if (specificTo.length > 0) {
for (int i = 0; i < specificTo.length; i++) {
if (a.before("</" + htmlStartTagString + ">").text().contains(specificTo[i])) {
Node node = a.nextSibling();
value = specificTo[i] + " --> " + node.toString().trim();
list.add(value);
}
}
}
else {
Node node = a.nextSibling();
value = node.toString().trim();
list.add(value);
}
}
return list.toArray(new String[list.size()]);
}
I have tried some code to check that user is already exist in database or not while doing registration. But I am getting error like this. What am I getting wrong?
I am using Netbeans 8.2, Apache Tomcat, and MySQL database (XAMPP).
This is my registration.jsp page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration JSP Page</title>
<style>
body {
background-color: lightblue;
}
#wgtmsrnew {
width: 153px;
}
</style>
<script>
function validateForm() {
alert("User Registered Successfully");
return true;
}
</script>
</head>
<body>
<form method="post" action="registrationJSPScript.jsp" onsubmit="return validateForm()">
<center>
<table border="1" width="30%" cellpadding="5">
<thead>
<tr>
<th colspan="2">Register</th>
<p><b>Please fill in this form to create an account.</b></p>
</tr>
</thead>
<tbody>
<tr>
<td>Z ID</td>
<td><input type="text" name="zid" value="" required="" /></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" value="" required="" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" value="" required="" /></td>
</tr>
<tr>
<td>Mail ID</td>
<td><input type="email" name="mailid" value="" required="" /></td>
</tr>
<td>Password</td>
<td><input type="password" name="pass" required="" value="" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!##$%^&*_=+-]).{8,12}$" required title="8 characters minimum,At least 1 Uppercase,At least 1 Lowercase,At least 1 number,At least 1 Symbol, symbol allowed --> !##$%^&*_=+-"
/></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
<tr>
<td colspan="2">Already registered!! Login Here</td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
You need to check first if your zid enter by user is already present or not using select query and then if user exist just put an alert ,else insert record in db and your code will look like somewhat below:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dmsqms","root", "");
Statement st = con.createStatement();
String sql = "SELECT * FROM dmsmembers WHERE zid=?";//getting username
PreparedStatement ps=con.prepareStatement(sql);
//setting value for ?
ps.setString(1,zid);
ResultSet rs = ps.executeQuery();
//checking if record with zid exist if yes do below
if(rs.next()){
//put alert here
out.println("<script type=\"text/javascript\">");
out.println("alert('User Already Exists');");
out.println("</script>");
}else{
//if zid doesn't exist insert new record
int i = st.executeUpdate("insert into dmsmembers(zid, first_name, last_name, mailid, department, division, location, pass, regdate) values ('" + zid + "','" + fname + "','" + lname + "','" + email + "','" + department + "','" + division + "','" + location + "','" + pwd + "', CURDATE())");
if (i > 0) {
//response.sendRedirect("loginJSP.jsp");
//insert successfull alert message and redirect
out.println("<script type=\"text/javascript\">");
out.println("alert('Registration Successfull!');");
out.println("location='loginJSP.jsp';");
out.println("</script>");
} else {
//not inserted have some error print here
}
}
} catch(Exception e){
//print error if any
e.printStackTrace();
}
Use try-catch block.It will work .
I have 2 classes:
public class IndividualRate {
private String currency;
private String operation;
private double rate;
private double amount;
//controller, getters and setters
}
public class IndividualRateList {
private List<IndividualRate> individualRates = new ArrayList<>();
//controller, getters and setters
}
In JSp I have table and form tag for sending data to Spring:
<tbody id="rateBody">
<form:form method="POST" cssClass="forms" id="formRateSubmit" action="${urlRates}"
modelAttribute="individualRateList">
<tr id="row1">
<td>
<select name="individualRates[0].currency" id="listOfCurrency1">
<option selected="selected" value=""><spring:message code="label.please.select"/></option>
<c:forEach var="item" items="${currencyRates}" varStatus="loop">
<option value="${item.currency}" >${item.currency}</option>
</c:forEach>
</select>
</td>
<td>
<input type="radio" name="individualRates[0].operation" value="Buying" checked="true"/><spring:message code="label.buying.operation"/>
<input type="radio" name="individualRates[0].operation" value="Selling"/> <spring:message code="label.selling.operation"/>
</td>
<td>
<input type="text" name="individualRates[0].rate" id="txtRate1" size="10"/>
</td>
<td>
<input type="text" name="individualRates[0].amount" id="txtAmount1" size="10"/>
</td>
<td>
<a href="javascript:void(0);" id="deleteRow1" class="btn-remove"
style="color: #f00; text-decoration: none;" onclick="deleteRow('1')">X</a>
</td>
</tr>
<tr id="row2">
<td>
<select name="individualRates[1].currency" id="listOfCurrency2">
<option selected="selected" value=""><spring:message code="label.please.select"/></option>
<c:forEach var="item" items="${currencyRates}" varStatus="loop">
<option value="${item.currency}" >${item.currency}</option>
</c:forEach>
</select>
</td>
<td>
<input type="radio" name="individualRates[1].operation" value="Buying" checked="true"/><spring:message code="label.buying.operation"/>
<input type="radio" name="individualRates[1].operation" value="Selling"/> <spring:message code="label.selling.operation"/>
</td>
<td>
<input type="text" name="individualRates[1].rate" id="txtRate2" size="10"/>
</td>
<td>
<input type="text" name="individualRates[1].amount" id="txtAmount2" size="10"/>
</td>
<td>
<a href="javascript:void(0);" id="deleteRow2" class="btn-remove"
style="color: #f00; text-decoration: none;" onclick="deleteRow('2')">X</a>
</td>
</tr>
<%--</c:forEach>--%>
</form:form>
</tbody>
When I run this program both of 2 rows are sent to Spring. But the count of rows are mutable. I have button for adding new rows. If I comment second row (row2) and add this with addRow button second row isn't sent. The onClick function for addRow button:
$('#addRow').click(function () {
i = i + 1;
var row = document.getElementById("row1").cloneNode(true);
row.id = "row" + i;
var elementsInput = row.getElementsByTagName("input"); // 4 input tag
var elementSelect = row.getElementsByTagName("select"); // 1 select tag
//// Currency
elementSelect[0].id = "listOfCurrency" + i;
elementSelect[0].name = "individualRates[" + (i-1) + "].currency";
//// Operation
elementsInput[0].name = "individualRates[" + (i-1) + "].operation";
elementsInput[1].name = "individualRates[" + (i-1) + "].operation";
//// Rate
elementsInput[2].id = "txtRate" + i;
elementsInput[2].name = "individualRates[" + (i-1) + "].rate";
//// Amount
elementsInput[3].id = "txtAmount" + i;
elementsInput[3].name = "individualRates[" + (i-1) + "].amount";
document.getElementById("rateBody").appendChild(row);
});
Please, help me to solve this problem.
I amended a successfully working java-script to make it work in jsp with java. However, its not working as per expectation, here in jsp I am dynamically creating rows based on java hashmap input. Its giving me issues in jsp, but in html + javacsript its working as expected.
So basically, when I try to make a selection. The selection jumps from one row to another and I can't make 3 different selections. Sharing screenshot as well for reference.
PS: this is not html issue, and pardon my syntax issues if in jsp, as I am new to jsp. I spent many hours trying to fix this, if you can fix the jsp snippet I would be grateful to you!
This is my jsp snippet:
<tr align="left">
<td align="left"> <%out.println( tempsysDetails1.getCategory().get(i)); %> </td>
<td align="left"> <input type="radio" name="inlineRadioOptions_' + i + '[]" value="0" id="inlineRadio0"' +
$bean{tempsysDetails1.getSystemStatus().get(i)))== '0' ? ' checked="checked"' : '' )} + '><font color="black">Grey </font><label class="radio-inline">
<input type="radio" name="inlineRadioOptions_' + i + '[]" value="1" id="inlineRadio1"' + $bean{tempsysDetails1.getSystemStatus().get(i)))== '1' ? ' = 1 ? ' checked="checked"' : '') +
'><font color="green">Green </font><label class="radio-inline"><input type="radio" name="inlineRadioOptions_' + i + '[]" + id="inlineRadio2" value="2"' +
($bean{tempsysDetails1.getSystemStatus().get(i)))== '2' ? ' checked="checked"' : '' ) + '><font color="yellow">Yellow </font></label><label class="radio-inline">
<input type="radio" name="inlineRadioOptions_' + i + '[]" id="inlineRadio3" value="3"' +
$bean{tempsysDetails1.getSystemStatus().get(i)))== '3' ? ' checked="checked"' : '') + '> <font color="red">Red</font></label></td>
<td align="left"><input type="text" id= "comments[i]" class="form-control name_list" placeholder="<%out.println(tempsysDetails1.getComments().get(i)); %> "> </td>
</tr>
This is my working javascript + html.
$(document).ready(function() {
var appStatus = [{
"category": "Overall Status",
"status": "0"
}, {
"category": "System Availability",
"status": "1"
}, {
"category": "Whatever",
"status": "2"
}];
var tr;
for (var i = 0; i < appStatus.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + appStatus[i].category + "</td>");
tr.append('<tr id="row' + i + '"><td><input type="radio" name="inlineRadioOptions_' + i + '[]" value="0" id="inlineRadio0"' +
(appStatus[i].status == '0' ? ' checked="checked"' : '') +
'><font color="black">Grey </font><label class="radio-inline"><input type="radio" name="inlineRadioOptions_' + i + '[]" value="1" id="inlineRadio1"' +
(appStatus[i].status == '1' ? ' checked="checked"' : '') +
'><font color="green">Green </font><label class="radio-inline"><input type="radio" name="inlineRadioOptions_' + i + '[]" id="inlineRadio2" value="2"' +
(appStatus[i].status == '2' ? ' checked="checked"' : '') +
'><font color="yellow">Yellow </font></label><label class="radio-inline"><input type="radio" name="inlineRadioOptions_' + i + '[]" id="inlineRadio3" value="3"' +
(appStatus[i].status == '3' ? ' checked="checked"' : '') + '> <font color="red">Red</font></label><td></tr>');
//tr.append("<td>" + "<input>" + appStatus[i].comments + "</input>" + "</td>");
tr.append("<td>" + '<tr id="row' + i + '"><td><input type="text" id="appStatus[i].comments" name="appStatus[i].comments" placeholder="Comments" class="form-control name_list" required' + "</td>");
$('table').append(tr); }
$('#result').on('click', function() {
var new_status = [];
$('.table tbody tr').each(function() {
new_status.push({
category: $(this).find('td:eq(0)').text(),
status: $(this).find(':radio:checked').val()
});
});
console.log(new_status);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-hover">
<thead>
<th>Category</th>
<th>Status</th>
<th>Comments</th>
</thead>
</table>
I got a scripts that convert google locations to google coordinates (lat/lng) and that works great.
My results are printed to a table with td and tr. Till now, everything works good.
But i want to print the results (The coordinates) also to another location in HTML.
I want that the results also printed to a table in XXXX. Optional also the location...
It is not working for me...
function getResultsListItem(resultNum, resultDescription) {
var html = '<a onclick="selectMarker(' + resultNum + ')">';
html += '<div class="info" id="p' + resultNum + '">';
html += '<table><tr valign="top">';
html += '<td style=""><img src="' + getMarkerImageUrl(resultNum) + '"/></td>';
html += '<td style="">' + resultDescription + '</td>';
html += '</tr></table>';
html += '</div></a>';
return html;
}
/**
* Get suggestions for a postcode with multiple localities.
* #param {!google.maps.GeocoderResult} resultDescription Geocoding result.
*/
function getPostcodeLocalitiesSuggestion(resultDescription) {
if (resultDescription.types.indexOf("postal_code") == -1) return "";
console.log(resultDescription.postcode_localities.length + " localities");
var postcode = resultDescription.address_components[0].long_name;
var html = '<span class="dym">Did you mean</span>: ' + '<span class="pc_localities">' + postcode + ' in ';
for (i in resultDescription.postcode_localities) {
var locality = resultDescription.postcode_localities[i];
html += '<a href="#' + escape(getPermalink(postcode + ' ' + locality)) + '">';
html += locality + '</a>';
html += (i == resultDescription.postcode_localities.length - 1 ? '.' : ', ');
}
return html;
}
/**
* Get a nicely formatted result description.
* #param {!google.maps.GeocoderResult} result Geocoding result.
*/
function getResultDescription(result) {
var bounds = result.geometry.bounds;
var html = '<table class="tabContent">';
html += tr('Address', result.formatted_address);
if (result.postcode_localities) {
html += tr('Localities', result.postcode_localities.join('<br/>'));
}
html += tr('Types', result.types.join(", "));
html += tr('Location', result.geometry.location.toString());
html += tr('Bounds', (bounds ? boundsToHtml(bounds) : "None"));
html += tr('Viewport', boundsToHtml(result.geometry.viewport));
html += tr('Location type', result.geometry.location_type);
if (result.partial_match) {
html += tr('Partial match', 'Yes');
}
html += '</table>';
return html;
}
The HTML with location and name...
<table width="90%" border="0">
<tr>
<td>Foto: *</td>
<td>
<input type="file" id="bestand" name="bestand">
</td>
</tr>
<tr>
<td>Boxname: *</td>
<td>
<input type="text" id="boxname" name="boxname">
</td>
</tr>
<tr>
<td>User: *</td>
<td>
<input type="text" id="user" name="user">
</td>
</tr>
<tr>
<td>Country: *</td>
<td>
<select name="categorie" id="categorie">
<option value=""> - Gelieve een Land te kiezen - </option>
<option value="<?php echo $categorie['categorie_id']; ?>">
<?php echo $categorie['naam']; ?>
</option>
</select>
</td>
</tr>
<tr>
<td>Location: *</td>
<td>
<textarea id="location" name="location"></textarea>
</td>
</tr>
<tr>
<td>Coordinates: *</td>
<td>
<textarea id="coordinates" name="coordinates"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" id="knop" name="knop" value="Add New Suezbox">
</td>
</tr>
</table>