www.webdeveloper.com
Results 1 to 8 of 8

Thread: Ajax

  1. #1
    Join Date
    Jan 2011
    Posts
    6

    Ajax

    below my java Script is there
    it is not entering after if(xmlObj.readystate == 4 & xmlObj.status == 200)
    please help me..,

    Code:
    function GetXmlHttpObject()
    {
    	var xmlHttp=null;
    	try
    	{
    		// Firefox, Opera 8.0+, Safari
    		xmlHttp=new XMLHttpRequest();
    	}
    	catch (e)
    	{
    		// Internet Explorer
    		try
    		{
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}catch (e)
    		{
    			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    	}
    	return xmlHttp;
    }
    var xmlObj = GetXmlHttpObject();
    
    function getCityData()
    {
    	var stateValue = document.getElementById("State").value;
    	
    	url = "http://localhost:8085/NewForm/getCity.jsp?State="+stateValue;
    	alert(url);
    	xmlObj.open("GET",url,true);
    	
    	xmlObj.onreadystatechange = function()	{  
    		//alert(xmlObj.status);
    		//alert(xmlObj.readystate);
    		alert(xmlObj);
    		if(xmlObj.readystate == 4 & xmlObj.status == 200)
    		
    		{
    					alert(xmlObj.readystate);
    			alert("jerald");
    			alert(xmlObj.responseText);
    			//var id =
    				document.getElementById("City");
    			
    			var result = xmlObj.responseText;
    			alert(result);
    				
    			var s = result.split(',');
    			var indx = 1;
    			for(indx=1; indx < s.length; indx++)
    			
    			{
    				document.form1.City.options[s[indx]] = new Option(s[2],s[1]);
    			
    			}
    			
    			}
    	}
    	xmlObj.send(null);
    }
    Last edited by Kor; 01-07-2011 at 08:57 AM. Reason: wrap the code [code][/code]

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Try alerting the relevant values:
    Code:
    xmlObj.onreadystatechange = function() { 
    alert(  this.readyState + '\n\n' + this.status )
    If you are testing locally and not under the http protocol, status will always be 0. To avoid that you could change your if() statement to:
    Code:
    if( this.readystate == 4 && ( !location.href.indexOf('http') ? this.status == 200 : true ) )


    Q: I found this code...
    A: Then find its author.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    At a first glace
    Code:
    if(xmlObj.readystate == 4 & xmlObj.status == 200)
    Should be:
    Code:
    if(xmlObj.readystate == 4 && xmlObj.status == 200)

  4. #4
    Join Date
    Jan 2011
    Posts
    6

    JSP with ajax please Help me as soon as possible

    Hi,
    I did it but i totally changed my code i'm not used xmlObj i used xmlHttp
    my coding are shown below

    function loadContent()
    {

    xmlhttp=GetXmlHttpObject();

    if (xmlhttp==null)
    {
    alert ("Your browser does not support Ajax HTTP");
    return;
    }

    var stateValue = document.getElementById("State").value;
    var url="getCity.jsp";
    url=url+"?State="+stateValue;

    xmlhttp.onreadystatechange=getOutput;
    xmlhttp.open("GET",url,true);


    xmlhttp.send(null);
    }


    function getOutput()
    {
    if (xmlhttp.readyState==4)
    {

    document.getElementById("City").innerHTML=xmlhttp.responseText;
    //alert(document.getElementById("City"));
    }
    }
    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
    {
    return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
    }

    but now i'm facing another problem this javascript goes to my getCity.jsp
    in that JSP i want to get C_ID and City Name but i want to display only the city name in the combo box2
    now i'm getting both the C_ID and city name in the combo box 2

    below my getCity.jsp are shown

    <%@ page import="java.sql.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.lang.*"%>
    <%@ page import="java.text.*"%>
    <%@page contentType="text/html" pageEncoding="UTF-8" language="java"%>

    <%
    String stateId = null;
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try
    {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    con = DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe","distil","distil");

    stateId = request.getParameter("State");

    String query = "select C_ID,CITY from mt2 where S_ID='"+stateId+"'";

    stmt = con.prepareStatement(query);

    rs = stmt.executeQuery();
    String City = null;
    while(rs.next())
    {
    City = "" + rs.getString(1) + " " + rs.getString(2);
    //City = ""+ rs.getString(1);
    }
    out.println(City);
    }
    catch (SQLException ex){
    System.err.println(ex.getMessage());
    }
    catch (Exception e){
    e.printStackTrace();
    }
    finally{
    //rs.close();
    //con.close();
    stmt.close();
    }
    %>

  5. #5
    Join Date
    Jan 2011
    Posts
    6

    Ajax for Oracle Date Validation Please Help me

    i want to write coding for date format for Oracle dd-mmm-yyyy in ajax.


    in the Form i put text box i converted string to Date format in server side.

    but my TL said to change the code in ajax or javaScript to validate the date in client side itself.


    Now i taken the code for nov-11-2011 how can i change that code for my format..

    my javascript for date is coming below


    function check(objName) {
    var datefield = objName;
    if (isDate(objName) == false) {
    datefield.select();
    alert("Invalid dates.");
    datefield.focus();
    return false;
    }
    else {
    return true;
    }
    }
    function isDate(objName) {
    var strDatestyle = "dd-mmm-yyyy";
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparadate2rArray = new Array("-"," ","/",".");
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = datefield.value;
    if (strDate.length < 1) {
    return true;
    }
    for (intElementNr = 0; intElementNr < strSeparadate2rArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparadate2rArray[intElementNr]) != -1) {
    strDateArray = strDate.split(strSeparadate2rArray[intElementNr]);
    if (strDateArray.length != 3) {
    err = 1;
    return false;
    }
    else {
    strDay = strDateArray[0];
    strMonth = strDateArray[1];
    strYear = strDateArray[2];
    }
    booFound = true;
    }
    }
    if (booFound == false) {
    if (strDate.length>5) {
    strDay = strDate.substr(0, 2);
    strMonth = strDate.substr(2, 2);
    strYear = strDate.substr(4);
    }
    }
    if (strYear.length == 2) {
    strYear = '20' + strYear;
    }
    if (strDatestyle == "dd-mmm-yyyy") {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
    }
    intday = parseInt(strDay, 10);
    if (isNaN(intday)) {
    err = 2;
    return false;
    }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
    if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
    intMonth = i+1;
    strMonth = strMonthArray[i];
    i = 12;
    }
    }
    if (isNaN(intMonth)) {
    err = 3;
    return false;
    }
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
    err = 4;
    return false;
    }
    if (intMonth>12 || intMonth<1) {
    err = 5;
    return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    return false;
    }
    if (intMonth == 2) {
    if (intday < 1) {
    err = 8;
    return false;
    }
    if (LeapYear(intYear) == true) {
    if (intday > 29) {
    err = 9;
    return false;
    }
    }
    else {
    if (intday > 28) {
    err = 10;
    return false;
    }
    }
    }
    if (strDatestyle == "dd-mmm-yyyy") {
    //datefield.value = strMonthArray[intMonth-1] + "-" + intday+"-" + strYear;
    datefield.value = intday + "-" +strMonthArray[intMonth-1]+"-" + strYear;

    }
    else {
    datefield.value = intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
    }
    return true;
    }
    function LeapYear(intYear) {
    if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
    }
    else {
    if ((intYear % 4) == 0) { return true; }
    }
    return false;
    }
    function doDateCheck(dil_ProjectStartDate, dil_ProjectEndDate) {
    if (Date.parse(dil_ProjectStartDate.value) <= Date.parse(dil_ProjectEndDate.value)) {
    alert("The dates are valid.");
    }
    else {
    if (dil_ProjectStartDate.value == "" || dil_ProjectEndDate.value == "")
    alert("Enter date.");
    else
    alert("Date of joining must be greater than date of birth.");
    }
    }




    <td><font size="5">Project Start Date</td>
    <td><input type="text" size="20" name="dil_ProjectStartDate" onBlur="check(this)">
    </td>
    <td><font size="5">Project End Date</td>
    <td><input type="text" size="20" name="dil_ProjectEndDate" onBlur="check(this)">
    </td>
    Please Help ME

  6. #6
    Join Date
    Jan 2011
    Posts
    6

    Please Help Me(JSP,JavaScript)

    hi i have written the program for generating dynamic combo box.

    i created 3 table for state mt1(table name),City mt2,Area mt3.

    using ajax i have generated dynamic combo box but in the database it store only the ID not the select character..,


    what i want to do...,

  7. #7
    Join Date
    Jan 2011
    Posts
    6

    Post Please Help Me

    Please Help Me...
    Reply for my thread..,

  8. #8
    Join Date
    Jan 2011
    Posts
    6

    Post Date Format in JavaScript Please Help

    this My Date validation JavaScript for this code Date Format is Jan-22-11(MMM-dd-yy) but i need dd-MMM-yy dis Format
    Please go through my code and say where i want to change code to get dd-MMM-yy.

    Please Help ME

    function check(objName) {
    var datefield = objName;
    if (isDate(objName) == false) {
    datefield.select();

    alert("Invalid dates.");
    datefield.focus();
    return false;
    }
    else {
    return true;
    }
    }
    function isDate(objName) {
    var strDatestyle = "dd-MMM-yy";
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparadate2rArray = new Array("-"," ","/",".");
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = datefield.value;
    if (strDate.length < 1) {
    return true;
    }
    for (intElementNr = 0; intElementNr < strSeparadate2rArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparadate2rArray[intElementNr]) != -1) {
    strDateArray = strDate.split(strSeparadate2rArray[intElementNr]);
    if (strDateArray.length != 3) {
    err = 1;
    return false;
    }
    else {
    strDay = strDateArray[0];
    strMonth = strDateArray[1];
    strYear = strDateArray[2];
    }
    booFound = true;
    }
    }
    if (booFound == false) {
    if (strDate.length>5) {
    strDay = strDate.substr(0, 2);
    strMonth = strDate.substr(2, 2);
    strYear = strDate.substr(2);
    }
    }
    if (strYear.length == 2) {
    //strYear = '20' + strYear;
    strYear = strYear;
    }
    if (strDatestyle == "dd-MMM-yy") {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
    }
    intday = parseInt(strDay,10);
    if (isNaN(intday)) {
    err = 2;
    return false;
    }
    intMonth = parseInt(strMonth,10);
    if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
    if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
    intMonth = i+1;
    strMonth = strMonthArray[i];
    i = 12;
    }
    }
    if (isNaN(intMonth)) {
    err = 3;
    return false;
    }
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
    err = 4;
    return false;
    }
    if (intMonth>12 || intMonth<1) {
    err = 5;
    return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    return false;
    }
    if (intMonth == 2) {
    if (intday < 1) {
    err = 8;
    return false;
    }
    if (LeapYear(intYear) == true) {
    if (intday > 29) {
    err = 9;
    return false;
    }
    }
    else {
    if (intday > 28) {
    err = 10;
    return false;
    }
    }
    }
    if (strDatestyle == "dd-MMM-yy") {
    //datefield.value = strMonthArray[intMonth-1] + "-" + intday+"-" + strYear;
    datefield.value = intday + "-" +strMonthArray[intMonth-1]+"-" + strYear;

    }
    else {
    datefield.value = intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
    }
    return true;
    }
    function LeapYear(intYear) {
    if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
    }
    else {
    if ((intYear % 4) == 0) { return true; }
    }
    return false;
    }
    function doDateCheck(dil_ProjectStartDate, dil_ProjectEndDate) {
    if (Date.parse(dil_ProjectStartDate.value) < Date.parse(dil_ProjectEndDate.value)) {
    alert("The dates are valid.");
    }
    else {
    if (dil_ProjectStartDate.value == "" || dil_ProjectEndDate.value == "")
    alert("Enter date.");

    else
    alert("Date of Project Starting Date must be greater than Project Ending Date.");
    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles