Click to See Complete Forum and Search --> : code not working


sun_rise
10-11-2007, 05:23 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function modifyNullToBlank(temp)
{
if(trim(temp) == 'null')
{
temp='';
}
document.writeln(temp);

}

function removeSpaces(string) {
alert(string);
var tstring = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
tstring += splitstring[i];

return tstring;
}
</script>
</HEAD>

<BODY>
<textarea>
<script language="javascript">
modifyNullToBlank(removeSpaces('null'));
</script>
</textarea>
</BODY>
</HTML>


when i run this code, i get the full javascript code in the textarea !!
I am expecting blank in fact.

anything wrong in my function ?
any syntax error ?

I dont want to change this structure in fact.

THIS IS a GENERATED CODE in my system.
I want to give a fix to this existing code.

felgall
10-11-2007, 05:32 AM
Whatever you place between the <textarea></textarea> tags is treated as plain text - no HTML allowed.

If you want to assign something to the textarea content from javascript then you use

document.formname.textareaname.value = 'textarea content that you want';

where formname is the value from the name attribute of the form tag that surrounds the textarea and textareaname is the value from the name attribute on the textarea tag.

sun_rise
10-11-2007, 05:39 AM
modified code ....still not working


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function modifyNullToBlank(temp)
{
if(trim(temp) == 'null')
{
temp='';
}
document.ABC.comments = temp;
//document.writeln(temp);

}

function removeSpaces(string) {
alert(string);
var tstring = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
tstring += splitstring[i];

return tstring;
}
</script>
</HEAD>

<BODY>
<form name="ABC">
<TEXTAREA Name="comments" rows="4" cols="20">
<script language="javascript">
modifyNullToBlank(removeSpaces('null'));
</script>
</TEXTAREA>
</form>
</BODY>
</HTML>

Tweak4
10-12-2007, 01:35 PM
Go back and carefully re-read Felgall's response.

Then take a look at the code you posted- specifically this part:

<TEXTAREA Name="comments" rows="4" cols="20">
<script language="javascript">
modifyNullToBlank(removeSpaces('null'));
</script>
</TEXTAREA>


The reason it won't work is because you're trying to execute code inside of your text area, which does not work.
As a result, you'll need to run your script elsewhere in the page, and then uses JS to set the value of the text area to the desired contents.

drhowarddrfine
10-12-2007, 08:26 PM
Also, your doctype is incomplete and IE is in quirks.