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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to delete null?

    I have created a HTML page with Load button, Save button and a Input text box. User can save the data that has been typed in the input text by clicking the Save button. To retrieve it, user can clicking the Load button.

    The problem I'm facing now is even though i haven't enter anything in the input text box, but when I click the Load button, the words "null" will be appeared in it. It should not have anything in the input text box when Load button is clicked if user haven't enter anything yet.

    So, what should be done to remove the words "null"?

    Below is my coding:

    Code:
    <script>
    function fnSaveInput(){
    	var filename="try"+"_message";
    	var oPersist=oPersistForm.oPersistText;
    	oPersist.setAttribute("sPersistText",oPersist.value);
    	oPersist.save(filename);
    }
    
    function fnLoadInput(){
    	 var filename="try"+"_message";
    	 var oPersist=oPersistForm.oPersistText;
    	 oPersist.load(filename);
             oPersist.value=oPersist.getAttribute("sPersistText");
    }
    Hope someone could help me. Thanks.
    Last edited by apple; 02-02-2005 at 10:48 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use an if() statement to check for null before assigning the value...
    *this message will self destruct in n-seconds*

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried with the if statement but still not working.

    Code:
    function fnSaveInput(){
    	var filename="try"+"_message";
    	var oPersist=oPersistForm.oPersistText;
    	oPersist.setAttribute("sPersistText",oPersist.value);
    	oPersist.save(filename);
    }
    
    function fnLoadInput(){
    	 var filename="try"+"_message";
    	 var oPersist=oPersistForm.oPersistText;
    	 oPersist.load(filename);
             if (oPersist.value==null){	
    		oPersist.value="";
    	 }else{	
    	 	oPersist.value=oPersist.getAttribute("sPersistText");  
    	 }	
    }

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What does typeof oPersist.getAttribute("sPersistText") return? If it's a string, then check for "null"...
    *this message will self destruct in n-seconds*

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you give me some idea of how to check for the string?

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    alert(typeof oPersist.getAttribute("sPersistText"));
    *this message will self destruct in n-seconds*

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How to check the condition if it is a string?

    Could you give me some idea again?

    Thanks.

  • #8
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function fnLoadInput(){
    	 var filename="try"+"_message";
    	 var oPersist=oPersistForm.oPersistText;
    	 oPersist.load(filename)
    	alert(typeof oPersist.getAttribute("sPersistText"));
    }
    *this message will self destruct in n-seconds*

  • #9
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I already tried with this. Alert only shows the type of oPersist.

    If it is a string and is null and i want to delete the words "null", what should be done?

  • #10
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's the type?

    object?... var foo = oPersist.getAttribute("sPersistText"); if(foo) oPersist.value= foo;
    Last edited by codegoboom; 02-02-2005 at 12:12 PM. Reason: null
    *this message will self destruct in n-seconds*

  • #11
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I posted my exmple here. Could u have a look?

    Thanks.
    Attached Files Attached Files
    Last edited by apple; 02-21-2005 at 01:45 AM.

  • #12
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do I have to?

    What's the @#$! type?
    *this message will self destruct in n-seconds*

  • #13
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do u mean by that?

    Please delete the previous example i have posted earlier and download the new if you have downloaded.
    Last edited by apple; 02-02-2005 at 12:57 PM.

  • #14
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by apple
    What do u mean by that?
    I'd really like you to put some effort into this nonsense...
    *this message will self destruct in n-seconds*

  • #15
    New Coder
    Join Date
    Jan 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i already tried but still not working.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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