First of all, please learn to post. NetNews is thread-based; you should
post a followup to the text you are directly referring to, provide
attribution of quoted material (in Google Groups: show options, Reply),
and trim your quotes to the minimum necessary to retain context:
<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
That said, for the flaw in its Web interface, posting with Google Groups is
recommended against anyway. Use a decent newsreader application instead.
news:news.software.readers
__________________________________________________ _________________________
david.lindsay.green@gmail.com wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You better use your name here.
[color=blue]
> Ok, thanks for the replies although a lot of it was over my head. I
> have been learning web scripting for 3 or 4 days now so be please dumb
> it down a bit.[/color]
I will try. However, never hesitate to ask explicitly about things you do
not (fully) understand.
[color=blue]
> I think my problem is
>
> [Julian Turner wrote:][color=green]
> > (b) when you extract the contents of a TEXTAREA using the BOM, the
> > Javascript String does not contain all of the "special characters" you
> > expect it to. In which case, can you be explicit as to which
> > characters are causing a problem for you. A Javascript String consists
> > of 16bit characters, and so can represent unicode values from 0000 to
> > FFFF I think.[/color]
>
> and it is the "+" symbol that I seem to be missing, at least thats the
> only one missing from my short test latex file.[/color]
Because you are including it in the request URI, even though you are
using POST. The plain `+' character is considered a substitute for the
space character in the query component by many server-side applications,
including PHP.
[color=blue]
> [Thomas 'PointedEars' Lahn wrote:][color=green]
> > (La)TeX source is plain text, I do not see why that would be relevant.
> > Are confusing the source code with the output it generates?[/color]
>
> When I say special characters I mean things like "+/!$&<" not things
> like alpha, beta, gamma etc you see in LaTex output.[/color]
Of those characters, only `+' and `&' can be considered special, and only
within the query component of a URI. (See above for the `+' character.)
The `&' character is the delimiter between each parameter of the component,
so it must be escaped if it does not serve as such (see RFC3986; you do
this already).
[color=blue]
> I believe my problem may lie in either the way I am retrieving the
> contents of the textarea or in the way i am saving it to a file.[/color]
Your assumption is correct.
[color=blue]
> <html>[/color]
The DOCTYPE declaration is missing before this, so the markup is not Valid.
<URL:http://validator.w3.org/>
[color=blue]
> <head>
> <script language="javascript" type="text/javascript">[/color]
You can safely omit the deprecated `language' attribute. You must omit it
with a Strict (X)HTML document type.
[color=blue]
> function loadtex(url){
> var xmlHttp = new XMLHttpRequest();[/color]
See below.
[color=blue]
> xmlHttp.open('GET',url,true);
> xmlHttp.onreadystatechange=function(){ setsource(xmlHttp); };[/color]
Unless you are planning to reuse setsource() somewhere, there is no need to
call it. You can simply use its code as code of the anonymous function.
[color=blue]
> xmlHttp.send(null);
> }
>
> function setsource(xmlHttp){
> if(xmlHttp.readyState==4){
> if (xmlHttp.status==200){
> var response = xmlHttp.responseText;
> document.getElementById("texSource").value=respons e;[/color]
Use a `form' element to contain the form controls, and pass `this.form' as
second argument to the method, say `f'. Then you can refer to the control
within the method by
f.elements['texSource'].value = response;
However, you would not need the "texSource" ID here:
f.elements['tex source'].value = response;
("tex source" is the current name of the control) would work as well.
[color=blue]
> }
> }
> }
>
> function savetex(){
> var updtSrc = escape(document.getElementById("texSource").value) ;[/color]
See above.
[color=blue]
> var urlS = 'save.php?content='+updtSrc;[/color]
You are doing this the wrong way.
Although specified different, there is a limit on URI length in some
browsers (IE is especially restrictive here). So on request what is
properly evaluated from 'save.php?content='+updtSrc by the script
engine is truncated for longer LaTeX code anyway.
[color=blue]
> var svHttp = new XMLHttpRequest();[/color]
This will not work in Internet Explorer before version 7 beta 2+.
See <URL:http://jibbering.com/2002/4/httprequest.html> for details.
[color=blue]
> svHttp.open('POST',urlS,true);[/color]
Using POST is the correct approach to work around the URI length limit,
however then you do not need to use the query component anymore:
var urlS = 'save.php';
[color=blue]
>[/color]
svHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
Opera 8+ supports XMLHTTPRequest, but Opera 8.0 does not implement the
setRequestHeader() method yet. (It is supported since version 8.01.)
[color=blue]
> svHttp.send(updtSrc);[/color]
svHttp.send("content=" + updtSrc);
[color=blue]
> }
> </script>
> </head>
>
> <body>
> <table border="1" width=100%>[/color]
Consider not using tables here, and learn to use CSS.
[color=blue]
> <tr><td><center>[/color]
You are looking for <td style="text-align:center"> instead of the deprecated
`center' element.
[color=blue]
> <INPUT type=button value="Load LaTex Source"
> onclick="loadtex('sample.tex')">[/color]
Whenever you use event handler attributes such as `onclick', you should
declare the default scripting language in the 'head' element:
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>
[color=blue]
> </center></td></tr>
> <tr><td>
> <br>[/color]
Do not use the `br' element to achieve margins. Use the CSS `padding' and
`margin' properties instead.
[color=blue]
> <center>[/color]
See above.
[color=blue]
> <textarea name="tex source" id="texSource", cols=80,[/color]
^ ^[color=blue]
> rows=35></textarea>[/color]
You are confusing programming and markup language here. Commas are not
allowed within a (start) tag outside of CDATA attribute values. They may
be ignored, but one should not depend on that. Remove them.
Attribute values should always be single-quoted or double-quoted. Although
not required, maybe it is better for later element object access to replace
the space in the name with an underscore (_) or, if you omit the ID
attribute as rendered redundant by my suggestion above, just remove the
space. You should have a preference for lowercase names and IDs.
[color=blue]
> </center></td></tr>
> <tr><td><center>[/color]
See above.
[color=blue]
> <INPUT type=button value="Save Source" onclick="savetex()">
> </center></td></tr>
> </table>
> </body>
> </html>
>
> save.php
>
> <?
> $datevar=date("YmdHms");
> $array1=array($datevar,'.tex');[/color]
This is unnecessary, see below.
[color=blue]
> $stuff=stripslashes($_GET['content']);[/color]
This line removes all backslashes (e.g. from "\tilde{}"):
<URL:http://de.php.net/manual/en/function.stripslashes.php>
Do not use stripslashes() here.
Use $_POST instead of $_GET here (see above).
[color=blue]
> $filename=implode($array1);[/color]
Unnecessary inefficient. Consider
$filename = date('YmdHms') . '.tex';
instead.
[color=blue]
> $f=fopen($filename,"w");
> fwrite($f,$stuff);
> fclose($f);
> ?>[/color]
You should test whether fopen() was successful before you fwrite() and
fclose():
$f = fopen($filename, "w");
if ($f)
{
fwrite($f, $stuff);
fclose($f);
}
HTH
PointedEars