...

View Full Version : How to delete null?



apple
02-02-2005, 10:08 AM
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:


<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.

codegoboom
02-02-2005, 11:24 AM
Use an if() statement to check for null before assigning the value...

apple
02-02-2005, 11:29 AM
I have tried with the if statement but still not working.


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");
}
}

codegoboom
02-02-2005, 11:34 AM
What does typeof oPersist.getAttribute("sPersistText") return? If it's a string, then check for "null"...

apple
02-02-2005, 11:39 AM
Could you give me some idea of how to check for the string?

codegoboom
02-02-2005, 11:48 AM
alert(typeof oPersist.getAttribute("sPersistText"));

apple
02-02-2005, 11:55 AM
How to check the condition if it is a string?

Could you give me some idea again?

Thanks.

codegoboom
02-02-2005, 11:59 AM
function fnLoadInput(){
var filename="try"+"_message";
var oPersist=oPersistForm.oPersistText;
oPersist.load(filename)
alert(typeof oPersist.getAttribute("sPersistText"));
}

apple
02-02-2005, 12:02 PM
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?

codegoboom
02-02-2005, 12:08 PM
What's the type?

object?... var foo = oPersist.getAttribute("sPersistText"); if(foo) oPersist.value= foo;

apple
02-02-2005, 12:40 PM
I posted my exmple here. Could u have a look?

Thanks.

codegoboom
02-02-2005, 12:53 PM
Do I have to? :D


What's the @#$! type? :p

apple
02-02-2005, 12:54 PM
What do u mean by that?

Please delete the previous example i have posted earlier and download the new if you have downloaded.

codegoboom
02-02-2005, 12:59 PM
What do u mean by that?
I'd really like you to put some effort into this nonsense... ;)

apple
02-02-2005, 01:01 PM
i already tried but still not working.

codegoboom
02-02-2005, 01:07 PM
Prove it. Justify your reasoning...

apple
02-02-2005, 01:10 PM
I don't understand why the words "null" is appear when I clicked on the Load button even though i haven't enter anything yet.

I have tried to use oPersist.value = "" to delete it but still can't.

codegoboom
02-02-2005, 01:13 PM
We've just gone in a circle. Try backtracking... :)

apple
02-02-2005, 01:15 PM
Ok.Thanks for your reply.

apple
02-02-2005, 02:10 PM
codegoboom, I finally solved the problem. Thanks.

codegoboom
02-02-2005, 02:15 PM
I knew you could. :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum