SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    display cross icon with message

    hi all

    The below code checks whether user already exists or not and echo the message accordingly

    I m having trouble displaying a cross icon image with message if user already exists.

    otherwise i dont want to show any message or may be remove message holder.

    If i use insert image then the error i get is "undefined."

    otherwise message is displayed fine.

    vineet

    PHP 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 username already exists.'/* this displays message fine */
                
                
    echo '<img src="images/cross_small.gif" alt="" />Sorry! This Login-ID already exists.'
                
    /* But if i use image then message is displayed as "undefined"*/
            
    }else{ 
                echo 
    '.';  
            } 
            echo 
    '</result>'
            
    ?>

    this is message display holder
    Code:
    <span id="userlogin_error"></span>

    this is ajax script

    Code:
    if(handle.value.length > 0) { 
            var fullurl = url + 'do=check_username_exists&username=' + encodeURIComponent(handle.value); 
            http.open("GET", fullurl, true); 
            http.send(null); 
            http.onreadystatechange = statechange_username; 
        }else{ 
            document.getElementById('userlogin_error').innerHTML = ''; 
        } 
    } 
    
    function statechange_username() { 
        if (http.readyState == 4) { 
            var xmlObj = http.responseXML; 
            var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; 
    		document.getElementById('userlogin_error').innerHTML = html; 
    		
        } 
    }

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm thinking that you're ending up with invalid xml when you put the <img> tag in there. That error seems to be saying that
    xmlObj.getElementsByTagName('result').item(0).firstChild.data
    is undefined.

    You'll have to debug there. Check the result of each part. Is xmlObj.getElementsByTagName('result') what you expect? etc.
    - Robert


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
  •