|
Please do not just dump a load of unformatted code and expect someone to figure out what it is supposed to be doing. Edit your question and explain the problem properly, with only the relevant portions of the code, properly enclosed within <pre> tags for readability.
|
|
|
|
|
-------------------------------------index.jsp-----------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/javascript">
var req;
function initReq(){
if(window.XMLHttpRequest){
req=new XMLHttpRequest;
}else if(window.ActiveXObject){
req=new ActiveXObject("Microsoft.XMLHTTP");
}
}//initReq
function verifyUname(){
initReq();
var sid=document.getElementById("uname").value;
var url="checkunm.jlc?uname="+escape(uname);
req.open("GET",url);
req.onreadystatechange=processResponse;
req.send();
}
function processResponse(){
var st=req.readyState;
var resSt=req.status;
if(st==4 && resSt==200){
displayResult();
}
}//processResponse
function displayResult(){
document.getElementById("error").innerHTML="";
document.getElementById("result").innerHTML="";
var array=req.responseText;
var data=eval('('+array+')');
if(data.length==0){
document.getElementById("error").innerHTML="<font color='red' size='5'>no student found</font>";
}//if
else
{
for(var i=0;i<data.length;i++){
var jsob=data[i]; <<<<<<<<<<<<<< ----here value is not coming it is getting 0 each time input----------------
document.write(jsob.msg);
}
}
}
</script>
<body>
<form action="register.jlc" method="post">
<div id="result"></div>
<div id="error"></div>
<table>
<tr>
<td align="center" colspan="2">REGISTER HERE</td>
</tr>
<tr>
<td>
ENTER USERNAME
</td>
<td>
<input type="text" name="uname" id="uname" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td>
ENTER PASSWORD
</td>
<td>
<input type="password" name="password" id="password" onkeyup="verifyUname()"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="REGISTER"/>
</td>
</tr>
</table>
</form>
</body>
</html>
------------------------------CheckUnameServlet-------------------------------------------------
package com.jlcindia.ajax;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import java.io.IOException;
import java.util.*;
public class CheckUnameServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> unames=new ArrayList<String>();
public void init(ServletConfig config) throws ServletException{
unames.add("sri");
unames.add("lucky");
unames.add("piyush");
unames.add("ujjawal");
super.init(config);
}
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uname=req.getParameter("uname");
String msg="";
JSONArray array=new JSONArray();
if(uname!=null && uname.trim().length()>0){
JSONObject jobj=new JSONObject();
if(unames.contains(uname)){
try {
jobj.put(msg); <<<<<<<< -------------// here may be am doing wrong --------------
} catch (JSONException e) {
e.printStackTrace();
}
array.add(jobj);// <<<<<<<<< -------------// here may be am doing wrong --------------
System.out.println(array);
}
}
System.out.println(array.toJSONString());
res.setContentType("application/json");
res.getWriter().write(array.toString());
}
}
-----------------------web.xml------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Test2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>cuServlet</servlet-name>
<servlet-class>com.jlcindia.ajax.CheckUnameServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cuServlet</servlet-name>
<url-pattern>/checkunm.jlc</url-pattern>
</servlet-mapping>
</web-app>
-- modified 23-May-17 7:24am.
|
|
|
|
|
sorry for the inconvinience plz help m out i reposted my question with proper formatt
|
|
|
|
|
No, you have just dumped the same totally unformatted code. Please stop doing this. Post only the code (enclosed within <pre>) that demonstrates your problem, as I already suggested. And please add a proper description of your problem.
|
|
|
|
|
Is there a compelling reason that you're developing for HTML4?
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
Hi,
I have two JSON objects:
JSON Object 1
[{
"date":
[
"date-value1",
"date-value2,
........ ,
"date-value729"
]
}]
JSON Object 2
{
"data": [
{
"body": [ "body1" ],
"link": "link1",
"title": [ "title1" ]
},
...........
{
"body": [ "body729" ],
"link": "link729",
"title": [ "title729" ]
}
]
}
How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:
{
"data": [
{
"body": [ "body1" ],
"link": "link1",
"title": [ "title1" ].
"date": "date1"
},
...........
{
"body": [ "body729" ],
"link": "link729",
"title": [ "title729" ]
"date": "date729"
}
]
}
Examples that I found online are mainly about merging two identical JSON objects.
Thank you in advance for your time and consideration.
|
|
|
|
|
I already answered this in the C# forum; please do not repost. And please make up your mid, is this C# or Javascript?
|
|
|
|
|
Let's look at the following code.
(function() {
var a = b = 5;
})();
console.log(b);
According to you, the output of the console output will look like?
|
|
|
|
|
If you do not know the answer, then either reread your reference guides, or run the code to see the results.
|
|
|
|
|
|
Press F12, go to Console window, enter that code there and press Enter. You will see the results yourself! I assure, that will be the correct answer, based on your browser's console.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
I want to write a effect like this.
But I don't know how to do it.
could somebody taught me? thanks a million!
image
modified 16-May-17 5:05am.
|
|
|
|
|
Here is an example:
function emailValidator(element, alertMsg){
var emailvalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(element.value.match(emailvalid))
{
return true;
}else{
alert(alertMsg);
element.focus();
return false;
}
}
element.focus() does not go back to the "Enter your email box" when a wrong email is enter, it goes to the next input box. Searched all over.
|
|
|
|
|
How is this function triggered?
You could try delaying the call to focus :
...
alert(alertMsg);
setTimeout(function(){ element.focus(); }, 100);
return false;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
Have a JSON file. Made it to work in IE 7 and 8. But need to make it work on IE 6.
Here is the script added.
var results = document.getElementById("apps");
var apps = new XMLHttpRequest();
apps.open("GET", "js/books.json", true);
apps.setRequestHeader("Content-type", "application/json", true);
apps.onreadystatechange = function() {
if (apps.readyState == 4 && apps.status == 200) {
var data = JSON.parse(apps.responseText);
results.innerHTML = "";
for (var app_content in data) {
content += data[app_content].authorname;
results.innerHTML += content;
}
}
For IE 7 and 8 have Added these reference files
Is there any way to make it work in IE 6.
Thanks
|
|
|
|
|
The native XMLHttpRequest object was first introduced in IE7.
If you need to support ancient browsers like IE6, then you'll need to fall-back to the ActiveX version:
var apps;
if (window.XMLHttpRequest) {
apps = new XMLHttpRequest();
}
else {
apps = new ActiveXObject("Microsoft.XMLHTTP");
}
Using XMLHttpRequest in IE6 - Web APIs | MDN[^]
Alternatively, use jQuery[^], which handles this sort of thing for you. But you'll need to stick to v1.12, since that was the last version that supported IE6 and IE7.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hy, I have typescript2 application. I use routing, su there are several separated components. Now here is a certain component where I retrieve JSON with html in it, render and it looks good. Now the problem is that there are some links it that JSON which renders but don`t work. I expected links to be working as fine as it works if you just staticaly add it to the template. Links should call functions that are in the same component which retrieves json from server.
I tried lots of examples on internet. But the result is errors or just rendering but nothing more.
There is only way I found to work is that when do this :
This component is in RouterModule.forRoot
@Directive({ selector: 'someevent' })
export class LibraryComponent implements OnInit,AfterViewInit {
@HostListener('click') button_pressed() {
this.getPeriods();
}
but the problem is that it works when I press everywhere on page. Not surprising, because IMO directive is decorated to the whole component in this case, not the exact element.
Then I tried to create separated class with directive as it should be, and I added ContentChild decorator because I need to get function (getPeriods()) as it is now in diferent component, but this doesn`t call function too, though no error found.
Can you help me in any ways?
modified 11-May-17 2:46am.
|
|
|
|
|
hy,
I have the following:
json file (fragment only):
"<span class=\"titel\">"
Component in ts:
styles: [`
titel {text-transform: uppercase;
color: #00467f;
font-weight: bold;
font-size: 14px;
}
`]
Now when I load the page the whole structure parses very well like
text , but for some reason text neither text becomes uppertexted nor color changes. Only works the style (like strong and links) in json file.
|
|
|
|
|
I am unsure of TS, but as far as I know, class names in CSS are prepended with a period (". "). So try that,
styles: [`
.titel {
text-transform: uppercase;
color: #00467f;
font-weight: bold;
font-size: 14px;
}
`]
Now try to run it and see if this works now.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hy,
I have angular2 typescript application with two language links and some menu items. All links and whole structure is on same app.component.ts . I use routing for menu. Now the problem is that I can`t change language after selecting one of the menu items, because IMO the component, the route looks for, becomes already used (after selecting menu), because I use links for changing language and menu items, which routes to the same components while having attributes routerLink. Is there any way to use the same component more than one time? All data we see after menu switch comes from database. So every routed component has its own text.
|
|
|
|
|
I wrote this little helper to make the textbox on a mobile device bigger when you select the textbox on a mobile phone.
I'm testing on an iPhone 6S+ large screen.
What exactly is touchend, say you touch the textbox and the keyboard comes up, "touchstart" which works fine, and my textbox gets larger;
but when I close the keyboard, the textbox stays large. I figured the touchcancel would fire or touchend.
$("input[type=text], input[type=password], textarea, select").on({
"touchstart click": function () {
zoomEnable();<br />
}
});
$("input[type=text], input[type=password], textarea, select").on({
"touchend touchcancel touchmove": function () {
setTimeout(zoomDisable, 500);
}
});
If it ain't broke don't fix it
|
|
|
|
|
So now the zoom works. but the zoom resets to normal after 3 seconds. I added the event and stopPropagation but it kills the code the the script dies.
I'm working off the production server on this, and the iPhone so I haven't figured out a way to detect script errors.
$("input[type=text], input[type=password], input[type=tel], textarea, select").on({
"touchstart click": function (event) {
event.stopPropagation(); event.preventDefault();
zoomEnable();
}
});
$("input[type=text], input[type=password], input[type=tel], textarea, select").on({
"touchend touchcancel touchmove": function () {
setTimeout(function () { zoomDisable(); }, 500);
}
});
If it ain't broke don't fix it
|
|
|
|
|
I don't understand why when touchstart fires, the keyboard loads and fires touchend.
And I can't find the event for when the keyboard unloads, it's not touchcancel.
$(":text, :password, input[type=tel], select").on({
"touchstart": function (event) {
$(this).css('border', 'solid 3px orange').val("touchstart");
event.stopPropagation();<br />
}
});
$(":text, :password, input[type=tel], select").on({
"touchend": function (event) {
$(this).css('border', 'solid 3px black').val("touchend");
}
});
$(":text, :password, input[type=tel], select").on({
"touchcancel": function (event) {
$(this).css('border', 'solid 3px red').val("touchcancel");
event.preventDefault();
}
});
If it ain't broke don't fix it
|
|
|
|
|