• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Entering HTML / XML tags in a Textarea tag

I am trying create an HTML form to accept XML / XSLT, and I'm having trouble getting the XML tags that people enter in the Textarea. When I submit the form, all I get is the text between the tags. For example, if someone enters: <tag>blah</tag> in the textarea, I only get "blah" when I retrieve the value of the textarea element. I am using Mason (Perl/HTML).

0
tarunsachdeva
Asked:
tarunsachdeva
1 Solution
 
mattjp88Commented:
<head>
<script>
function changetags() {
var text=document.frm1.text1.value;
var text1=text.split('<').join('&lt');
var text2=text1.split('>').join('&gt');
document.frm1.text1.value=text2;
//document.frm1.submit()
}
</script>
</head>
<body>
<form name=frm1>
<textarea NAME=text1></textarea><br>
<input TYPE="Button" VALUE=Submit onclick=changetags()>
</form>
</body>

matt :-)
0
 
gator4lifeCommented:
You might want to uncomment that last line of JavaScript in the changetags() function though, if you actually want the form to be submitted! ;-)

gator4life
(chomp, chomp)
0
 
sybeCommented:
I guess it is being submitted ok, but when you display <tag>blah</tag> in a browser, it will only show "blah", because HTML-tags are not displayed in a browser. Just look at the "view source" in your browser, and you'll see that everything is there.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
COBOLdinosaurCommented:
You better get the stings right in teh function:

var text1=text.split('<').join('&lt');
var text2=text1.split('>').join('&gt');


Should be:
var text1=text.split('<').join('&lt;');
var text2=text1.split('>').join('&gt;');


Unless you want it to display as:
&lttag&gtblah

Cd&
0
 
tarunsachdevaAuthor Commented:
Let me rephrase the question, because I'm not sure things are going to work with a Javascript based solution.

In my Mason file called "test.m", I have a form as such:

<form action=test.m method=post>
<textarea name="formdata" rows="10" cols="50"></textarea>
</form>

Later on in the file, in <%perl> blocks, I have:

<%perl>
               
my $xslt_form_result = $m->comp('form-handler.m', formdata => $form_data);

print $xslt_form_result;
</%perl>

Now, in my "form-handler.m", I try to access the formdata variable, which should have data that looks something like this (this is malformed XSLT, just written for this example):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<!--Add XSL HERE-->
<p align="left"><font color="000000">
<tr>
</tr>
<tr>
<xsl:for-each select="ProductInfo/Details">
....
<!--End of XSL-->
</xsl:template>
</xsl:stylesheet>

Now, the only thing I'm actually getting is the HTML tags, which are <p align="left">,<font>, and all that jazz. I'm not getting any of the <xsl:> tags when I try to access $formdata.

Thanks for any help.

-t
0
 
mattjp88Commented:
this isnt really HTML.  some of it is but most of it is Perl.  im no good with perl.  im out.

-Matt
0
 
tarunsachdevaAuthor Commented:
Actually, I found a way around things using your solution matt. Thanks.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now