Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: why does error message blinks onsubmit

  1. #11
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hi john

    thanks for the reply.

    how can i add a small "cross icon" before the message "sorry this login id already exists" in the below code

    Code:
    $count = mysql_num_rows(mysql_query("SELECT * FROM usertable WHERE `username`='".$username."'")); 
            header('Content-Type: text/xml'); 
            header('Pragma: no-cache'); 
            echo '<?xml version="1.0" encoding="UTF-8"?>'; 
    		echo '<result>'; 
            if($count > 0) { 
    		    echo 'Sorry! This Login-ID already exists.'; 
            }else{ 
                echo '.';  
            } 
            echo '</result>';
    this is ajax

    Code:
    function toggle_username(userid) { 
        if (window.XMLHttpRequest) { 
            http = new XMLHttpRequest(); 
        } else if (window.ActiveXObject) { 
            http = new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        handle = document.getElementById(userid); 
        var url = 'check_user.php?'; 
        if(handle.value.length > 0) { 
            var fullurl = url + 'do=check_username_exists&textbox1=' + 
    
    encodeURIComponent(handle.value); 
            http.open("GET", fullurl, true); 
            http.send(null); 
            http.onreadystatechange = statechange_username; 
        }else{ 
            document.getElementById('user_error').innerHTML = ''; 
        } 
    } 
    
    function statechange_username() { 
        if (http.readyState == 4) { 
            var xmlObj = http.responseXML; 
            var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; 
            document.getElementById('user_error').innerHTML = html; 
        } 
    }

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If I read that correctly there's always a:

    Code:
    xmlObj.getElementsByTagName('result').item(0).firstChild.data;
    If a dupe was found, it's the "Sorry . . ." message. If not it's just a dot (.).

    So you could test the length:

    Code:
    function statechange_username() { 
        if (http.readyState == 4) { 
            var xmlObj = http.responseXML; 
            var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; 
            html = html.length > 1? '<img src="crossicon.gif" alt="">' + html : '';
            document.getElementById('user_error').innerHTML = html; 
        } 
    }
    You could do that. An alternative would be to put the image tag into the xml document as it's being created. I'm uncertain of the proper syntax for that, but believe it can be done. There might be cross browser issues around that though. Inserting it where I've just shown, in the javascript part of the operation, would be the safest.

    Another approach would be to have the PHP code create an HTML fragment instead of an xml document, and have the statechange function use the responseText rather than the responseXML. Then it would be relatively easy to create cross browser HTML with the PHP script.

    PHP Code:
    <?php
    $count 
    mysql_num_rows(mysql_query("SELECT * FROM usertable WHERE `username`='".$username."'")); 
            
    header('Content-type: text/html; charset=utf-8'); 
            
    header('Pragma: no-cache'); 
            echo 
    '<span>'
            if(
    $count 0) { 
                echo 
    '<img src="crossico.gif" alt="">Sorry! This Login-ID already exists.'
            }
            echo 
    '</span>';
    ?>
    Code:
    function statechange_username() { 
        if (http.readyState == 4) { 
            document.getElementById('user_error').innerHTML = http.responseText;
        } 
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    vineet (10-05-2012)

  4. #13
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    thanks john

    Outputting the result as html instead of xml made the work really easy

    your are great

    vineet

Similar Threads

  1. Can anyone help with an error message?
    By Gemini23 in forum JavaScript
    Replies: 0
    Last Post: 01-13-2010, 07:41 PM
  2. Error Message in 3d spinning message
    By drgsb in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-24-2009, 06:36 AM
  3. XML error message
    By jendelaniaga in forum Dynamic Drive scripts help
    Replies: 25
    Last Post: 07-26-2008, 05:01 AM
  4. XML error message
    By kalxen in forum HTML
    Replies: 2
    Last Post: 04-10-2008, 02:04 PM
  5. Error message...
    By confusio in forum PHP
    Replies: 4
    Last Post: 07-08-2006, 03:19 AM

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
  •