Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Custom error/message boxes.

    Hey, I have a JavaScript function which displays a hidden div and fills it with an error message or just a general message.

    It's a bit messy at the moment, as creating the dialog using JUST JavaScript isn't too bad, as I can define the title easy enough (which will be either "Message" or "Error", and change the class to change the color.

    But sometimes I need to either display a message or error using results returned from an ajax request. At the moment i'm simply making the ASP return something along the lines off: "Error: An error has occurred".

    And then i'm stripping the word before the ":" to then define if the dialog is an error or just a message. Is there a better way of doing it at all?

    I was thinking of returning an input element and putting it in a hidden div. Then I can get the tag "name" which could contain either error/message, and then the value would be the message?

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    may as well post your code

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    It's a bit messy, this is what displays it and closes it. Different files are pulled in for errors and messages.

    PHP Code:
    //Load dialog
    function load_dialog(dialog,button,vars) {
        
    //Get http request object
        
    var http getHTTPObject();
        var 
    orig button.value;
        
        
    //Check ready state
        
    http.onreadystatechange = function () {
            if (
    http.readyState == 4) {
                if (
    http.status == 200) {
                    
                    
    //Display the result
                    
    if (button != false){ button.value orig}
                    
                    
    //Display the dialog
                    
    doc('blackout').style.visibility "visible";
                    
    doc('dialog').style.visibility "visible";
                    
                    
    //Ready, display the result
                    
    doc("dialog").innerHTML http.responseText;
                } else if (
    http.status == 404) {
                    
                    
    //File not found 
                    
    load_dialog("forms/error.asp?message=Error: File not found!<br /><br />Contact administrator.",false,1);    
                    
    doc('loading').style.visibility "hidden";
                }
            } else {
                
    //Change the button value to Loading...
                
    if (button != false){ button.value "Loading..."}
            }
        }
        
    //Any variables to send?
        
    if (vars == 1) {
            var 
    moreVars "&";
        } else {
            var 
    moreVars "?";
        }
        
    http.open("GET""http://localhost/nightclub_photography/" dialog moreVars Math.random(), true);
        
    http.send();
    }

    //Close the dialog, run additional JavaScript function after
    function closeDialog(dialogg,run) {
        
        
    //Clear the dialog and hide everything
        
    doc(dialogg).innerHTML "";
        
    doc('blackout').style.visibility "hidden";
        
    doc('dialog').style.visibility "hidden";
        
        
    //Run additional function?
        
    if (run) {
            eval(
    run);
        }

    And this is how it is called
    PHP Code:
    if (drive != "null") {
            var 
    http getHTTPObject();
            
    http.onreadystatechange = function() {
                if (
    http.readyState == && http.status == 200) {
                    
    doc('blackout').style.visibility "hidden";
                    
    //Check if it's an error or message
                    
    var http.responseText;
                    
    k.split(":");
                    
    k[0].toLowerCase();
                    
    load_dialog('forms/'+k+'.asp?message=' http.responseText1);
                } else {
                    
    doc('blackout').style.visibility "visible";
                }
            }
            
    http.open("GET""http://localhost/nightclub_photography/asp/upload.asp?drive="+drive+"&t="+Math.random());
            
    http.send();
        }
        return 
    false
    As you can see "k" is displaying the error/message. Uses a different file for errors and messages.


  •  

    Posting Permissions

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