insert javascrpt into textarea?

G

globalrev

i have a translator-program for the robbers language.

i want the user to input into the topwindow and then display the
encryption or decryption in the bottom window.

i am currently trying to do this via a python/webpy webapp but been
told it can be done with javascript.

how would i do this? i couldnt figure it out from the w3schools
tutorial.
and can i have a javascript to call another file? or i have to do the
translation in the html-file below? it could get very cluttery...

<html>
<body bgcolor="orange">

<center>
<h1><p><b>Robber's language encrypter/decrypter!</b></p></h1>

<form method=post>
<p>
<select name="encdec">
<option value="encrypt">encrypt</option>
<option value="decrypt">decrypt</option>
</select>
</p>
<textarea name="enc" rows="10" cols="50">
</textarea>
<p>
<input type="submit" value="submit" /><br />
</p>
</form>

<form method=post>
<textarea name="answer" rows="10" cols="50">

</textarea>
</form>

</center>
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

globalrev said:
i have a translator-program for the robbers language.

Your Shift key is malfunctioning.
i want the user to input into the topwindow and then display the
encryption or decryption in the bottom window.

i am currently trying to do this via a python/webpy webapp but been
told it can be done with javascript.

how would i do this? i couldnt figure it out from the w3schools
tutorial.

That is unsurprising, as the W3Schools people apparently don't know HTML
themselves. Avoid this site, it is not suitable as Web development reference.
and can i have a javascript to call another file? or i have to do the
translation in the html-file below? it could get very cluttery...

What I had to read below is very far from being a "html-file".
<html>
<body bgcolor="orange">

`orange' is not a valid value for the deprecated `bgcolor' attribute.

http://www.w3.org/TR/REC-html40/types.html#h-6.5
http://validator.w3.org/

CSS2 turns 10 tomorrow.

http://www.w3.org/TR/REC-html40/present/graphics.html#edef-CENTER
<h1><p><b>Robber's language encrypter/decrypter!</b></p></h1>

Not Valid, the `p' element must not be contained in the `h1' element.

http://www.w3.org/TR/REC-html40/struct/global.html#edef-H1
<form method=post>

Not Valid, the `action' attribute is required.

http://www.w3.org/TR/REC-html40/interact/forms.html#edef-FORM

Semantically wrong element, we are not talking paragraphs of text here. Use
`div' if you must.

http://www.w3.org/TR/REC-html40/struct/text.html#edef-P
http://www.w3.org/TR/REC-html40/struct/global.html#edef-DIV
<select name="encdec">

You should set the `size' attribute, too.

http://www.w3.org/TR/REC-html40/interact/forms.html#edef-SELECT
<option value="encrypt">encrypt</option>
<option value="decrypt">decrypt</option>
</select>
</p>
<textarea name="enc" rows="10" cols="50">
</textarea>
<p>
<input type="submit" value="submit" /><br />

You don't want to use XHTML.

http://hixie.ch/advocacy/xhtml
http://hsivonen.iki.fi/xhtml-the-point/
</p>
</form>

<form method=post>

See above.
<textarea name="answer" rows="10" cols="50">

</textarea>
</form>

You don't want to submit this form's information, so you don't need a form
element here.
</center>
</body>
</html>

As for your question, you can achieve optional client-side operation with

<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit()
{
...

// if successful
return false;
}
</script>
</form>

But I strongly suggest you learn HTML first.


PointedEars
 
G

globalrev

As for your question, you can achieve optional client-side operation with
<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit()
{
...

// if successful
return false;
}
</script>
</form>

But I strongly suggest you learn HTML first.

ty i know its not vaied html but i just threw it up quickly to learn
to handle this type of interaction.

where should the script be inserted?


id i do this, but want the script to write into the textarea instead,
how do i do that?


<html>

<script type="text/javascript">
function myfunction()
{
alert("HELLO");
}
</script>

<body>
<center>

<h1><p style="font-family:times new roman;color:eek:range">
<b>Robber's language encrypter/decrypter!</b>
</p></h1>

<p>
<select name="encdec">
<option value="encrypt">encrypt</option>
<option value="decrypt">decrypt</option>
</select>
</p>

<textarea name="enc" rows="10" cols="50">
</textarea>
s
<form>
<input type="button"
onclick="myfunction()"
value="submit">
</form>

</center>
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

globalrev said:
ty i know its not vaied html but i just threw it up quickly to learn
to handle this type of interaction.

You cannot expect invalid content to work; especially you cannot expect DOM
scripting to work within and on invalid markup.

http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you
where should the script be inserted?

I wrote that already.
id i do this, but want the script to write into the textarea instead,
how do i do that?

<html>

<script type="text/javascript">
function myfunction()
{
alert("HELLO");
}
</script>

It is still not Valid. The DOCTYPE declaration is missing, and while
the start and end tags for the `head' element are optional in HTML 4.01
Transitional, the `title' element within the `head' element is not.

http://validator.w3.org/
<body>
<center>

It is still deprecated (and is invalid with HTML 4.01 Strict).
<h1><p style="font-family:times new roman;color:eek:range">

The last item of a comma-separated `font-family' value should be a generic
font family (here: `serif') --

http://www.w3.org/TR/CSS2/fonts.html#propdef-font-family


PointedEars
 
G

globalrev

ok now i think it is, is there a site that can validate a htmlpage run
on my own computer(not a server or webhotel)?

so now if it is ok, how do i insert text upon submit into the textarea
or in another textarea below the now visible one?


also, how can i center the textarea vertically?


<html>
<head>
<title>robber's language</title>
<style type="text/css">
<!--
body {
margin: 0px;
padding: 0px;
}
#header {
background: #FDD017;
width: 100%;
height: 10%;
font-size: xx-large;
text-align: center;
}
#content {
background: white;
float: right;
width: 100%;
height: 90%;
text-align: center;
}
a:link {color: black; }
a:visited {color: white; }
a:hover {color: black; }
a:active {color: black; }
-->
</style>
</head>
<body>


<script type="text/javascript">
function myfunction()
{
alert("HELLO");
}
</script>


<div id="header">
<b>Robber's language encrypter/decrypter</b>
</div>
<div id="content">
<textarea rows="10" cols="30">
</textarea>


<form>
<input type="button"
onclick="myfunction()"
value="submit">
</form>


</div>
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

globalrev said:
ok now i think it is,

Is *what*?
is there a site that can validate a htmlpage run
on my own computer(not a server or webhotel)?
http://validator.w3.org/#validate-by-upload

so now if it is ok, how do i insert text upon submit into the textarea
or in another textarea below the now visible one?

Read my posting again.
also, how can i center the textarea vertically?

The most compatible way is to use a table cell:

<td style="vertical-align: middle">...-</td>

Further layout questions should be asked in the
comp.infosystems.www.authoring.* subhierarchy.


PointedEars
 
G

globalrev

just want to say i really appreciate your help. just find this
frustrating because its not really what i want to spend my time on,
want to spend it on my translator-program and just want a simple
working webapplication.
i guess also its fairly trivial once you know how to do it though.

now i have a valid strict html 4.01 document.

how do i take the text in the textarea when i press submit, then
transform the text and put it back in the window(or somehwere else).

the actual transformastion ill obv do by myself but how to take it and
send it back i need to know. there just is no clear example anywhere i
look on how to do this which is weird since it is standard procedure
on a lot of apps.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

<title>robber's language</title>
<style type="text/css">
<!--
body {
margin: 0px;
padding: 0px;
}
#header {
background: #FDD017;
width: 100%;
height: 10%;
font-size: xx-large;
text-align: center;
}
#content {
background: white;
float: right;
width: 100%;
height: 90%;
text-align: center;
}
a:link {color: black; }
a:visited {color: white; }
a:hover {color: black; }
a:active {color: black; }
-->
</style>
</head>
<body>

<div id="header">
<b>Robber's language encrypter/decrypter</b>
</div>
<div id="content">
<textarea name="enc" rows="10" cols="30">
</textarea>


</div>
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Read my posting again.

Especially my first followup. Obviously you will also need at least one
input control or a submit button within the `form' element, so that the form
can be submitted and its `submit' event created and handled by the
`onsubmit' attribute value.


PointedEars
 
G

globalrev

Especially my first followup. Obviously you will also need at least one
input control or a submit button within the `form' element, so that the form
can be submitted and its `submit' event created and handled by the
`onsubmit' attribute value.

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee




and obv i dont get it since i have read that several times already.
 
G

globalrev

<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit()
{
...

// if successful
return false;
}
</script>
</form>

should a textarea be place dinsid ehere? and a submitbutton? i dont
get it. seriously. call me stupid but...
 
T

Thomas 'PointedEars' Lahn

globalrev said:
<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit()
{
...

// if successful
return false;
}
</script>
</form>

should a textarea be place dinsid ehere? and a submitbutton? i dont
get it. seriously. call me stupid but...

<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit(f)
{
var es = f.elements;
var translation = translate(es['source'].value);
if (translation)
{
es['target'].value = translation;
}
else
{
// handle translation error
}

return false;
}
</script>
<div><textarea name="source" cols="80" rows="6"></textarea></div>
<div><input type="submit" value="Translate"></div>
<div><textarea name="target" cols="80" rows="6"></textarea></div>
</form>

Besides the fact that it must be within the `head' or `body' element, the
current location of the `script' element is really only my personal
preference: I like the script code to be near the form that it is operating on.


PointedEars
 
G

globalrev

globalrev said:
<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit()
{
...
// if successful
return false;
}
</script>
</form>
should a textarea be place dinsid ehere? and a submitbutton? i dont
get it. seriously. call me stupid but...

<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit(f)
{
var es = f.elements;
var translation = translate(es['source'].value);
if (translation)
{
es['target'].value = translation;
}
else
{
// handle translation error
}

return false;
}
</script>
<div><textarea name="source" cols="80" rows="6"></textarea></div>
<div><input type="submit" value="Translate"></div>
<div><textarea name="target" cols="80" rows="6"></textarea></div>
</form>

Besides the fact that it must be within the `head' or `body' element, the
current location of the `script' element is really only my personal
preference: I like the script code to be near the form that it is operating on.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16



thanks but when i write something and press translate i get handed to
another site. it doesnt write into the second textarea.
i understand the code but dont see how to change it. tried Translate
to translate in case it is case sensitive and to put
es['target'].value = translation; in the else in case it was just
wrong boolean logic.

but it always redirects to new "not found".
 
T

Thomas 'PointedEars' Lahn

[snipped attribution novel]
Thomas said:
<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit(f)
{
var es = f.elements;
var translation = translate(es['source'].value);
if (translation)
{
es['target'].value = translation;
}
else
{
// handle translation error
}

return false;
}
</script>
<div><textarea name="source" cols="80" rows="6"></textarea></div>
<div><input type="submit" value="Translate"></div>
<div><textarea name="target" cols="80" rows="6"></textarea></div>
</form>

Besides the fact that it must be within the `head' or `body' element, the
current location of the `script' element is really only my personal
preference: I like the script code to be near the form that it is operating on.
[...]

Will you please stop full-quoting?
thanks but when i write something and press translate i get handed to
another site. it doesnt write into the second textarea.

That can only be because you have not copied the code as is and forgot
either the `return false' or the `return' before handleSubmit(...).
i understand the code [...]

No, you don't. I suggest you start learning for real. NOW.

BTW, the pronoun `I' as well as the first character of the first word of a
sentence is spelled with a capital letter. I think the latter applies to
Swedish too, doesn't it?


Score adjusted

PointedEars
 
G

globalrev

You are the only one that writes with capitals on the internets ;).

Anyway I run the site from a python-app so thats why it redirected.

Launching the html-site by itself it doesnt redirect but it doesnt do
anything either.

Is it supposed to put anything I write in the toparea into the bottom
area?
 
G

globalrev

i got it to work now. thanks for all your help.


<form action="..." onsubmit="return handleSubmit(this)">
<script type="text/javascript">
function handleSubmit(f)
{
f.elements['target'].value = f.elements['source'].value;
}
</script>
<div><textarea name="source" cols="60" rows="10"></textarea></div>
<div><input type="submit" value="translate"></div>
<div><textarea name="target" cols="60" rows="10"></textarea></div>
</form>
 
D

Dr J R Stockton

In comp.lang.javascript message <4eb861ff-00ac-44d5-b12d-5aec8a556a8e@p2
5g2000hsf.googlegroups.com>, Sun, 11 May 2008 15:04:16, globalrev
ok now i think it is, is there a site that can validate a htmlpage run
on my own computer(not a server or webhotel)?

Download the free browser Opera, and Ctrl-Alt-V will submit the current
page to a W3 validator, over the net.

If you mean, however, that you want to validate your page without using
the Net at the time, then W3's TIDY can be used in check-only fashion.
Whether or not it is a full validator, it can certainly detect many
errors.

For more, see in my <URL:http://www.merlyn.demon.co.uk/www-use2.htm>; it
needs updating, but, as far as I can immediately see, it's satisfactory
as far as it goes.

<FAQENTRY>
Sec 2.3 needs something on the need for valid HTML.
Section 5 needs something about maintainers who have ceased maintaining.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top