SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to have multiple function to run thru a ajax page?

    hi

    i'm developing an online application where i list the customers and option to delete the customers.

    At first when i click the delete icon a confirm window is opened where if ok is clicked the click is further processed and if cancel is pressed it does nothing.


    When i click the delete icon a javascript function is called in which a php page is processed thru ajax .

    the php page gets the id as the input and returns some value either 0 or 1.

    Then if the true is returned i will popup another confirm window and if ok is clicked the customer will be deleted or if cancel is clicked then it does nothing, This is total scenario..


    And i used the following code.

    Code:
    <a class=delete href=# title="Click to delete this account" onClick="return Isconfirm(someid)"  >X</a>
    
    function Isconfirm(id)			
    {
        var  aid          = id;
        var  http_request = false;
        if (window.XMLHttpRequest)  // For Mozilla, Safari,...
            http_request = new XMLHttpRequest();
        else if (window.ActiveXObject)  // For IE
        {
          try
          {
               http_request = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
            try {
                 http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
          }
        }
        if (!http_request)
        {
          alert('Giving up :( Cannot create an XMLHTTP instance)');
          return false;
        }
        
        http_request.onreadystatechange = function() {s=alertContents(http_request);};
        http_request.open('GET', "./getcusid.php?id="+aid, true);
        http_request.send(null);
        alert(typeof s);
        if(s === false)
        {
    	alert("not entered");
    	return false;
        }
        else
        {
    	alert("Entered");
    	return true;
        }
    }
    
    function alertContents(http_request)
    {
      if (http_request.readyState == 4)
      {
        if (http_request.status == 200)
        {
          var tid = http_request.responseText;
          var res = confirm('Are you Sure you want to delete this customer?');
          if(res && tid!=0)
               var res1 = confirm('The selected customer has a non-zero balance.Deleting this customer will cause an adjustment to be created.Is this Ok?');
         else 
        	return false;
         if (res1)
           return true;
         else 
         return false;
       }
       else
        alert('There was a problem with the request.');
    }
    }
    On the whole if the user clicks the ok for all the popups then finally 'true' should be returned else on any other coditions 'false' should be returned..

    I think i 've done some mess on the code...

    It's not properly working ,please help me..
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  2. #2
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there anyone to review or reply?
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is your question? How about isolating the problem and asking again?


Bookmarks

Posting Permissions

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