SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: jQuery Issue

  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    jQuery Issue

    Hi jQuery Gurus,

    This is a very interesting question.

    I have a drop down box and a button on page1.php

    Clicking on that button adds whatever it is in the dropdown in the database.

    I am using the following jQuery on page1.php


    Code:
    <script>
    $(document).ready(function(){
    
    
    
    	$("#add").click(function(){
    	$(".status").html("Adding. Please Wait...").show("slow");
    		$.get("page2.php",{txtDropDown:$("#txtDropDown").val(),action:'add'},function(data){$("#quote").html(data);$(".status").html("Added Successfully.").hide("slow");})
    		return false;
    	});//Submit function
    	
    	
    
    
    
    
    });//Ready function	
    
    </script>
    - The .status div will show the current status. Like data added, data deleted, data updated successfully messages
    - The #quote div will display the added items.
    - Page2.php is doing all the processing.



    Now I have managed to program page2.php that it will not add one data more then once, How do I now display a message in the .status div that the item is already added in the database and that u cannot add the same item again?



    Thanx

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your PHP script should return the status on whether record was successfully added or not.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    yeah but that way the error would appear in the #quote div instead of the .status div.

    There is no way to display the error on the .status div?

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can return the status from the server.

    Code:
    function(data) {
      var parts = data.split(':');
      $("#quote").html(parts[0]);
      $(".status").html(parts[1]).hide("slow");
    }
    Live example:
    http://www.witlets.com/jquery-parse-...lements-1.html
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?


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
  •