Click here to get back home

How to do the same without javascript ?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to do the same without javascript ? Asterbing 05-21-2007
Get Chitika Premium
Posted by Asterbing on May 21, 2007, 5:33 am
Please log in for more thread options


Already posted in comp.lang.javascript but not found any solution :-(
--

Hi all,

Don't know where to ask my question because the way to go is included in
the possible answer itself by nature... You'll understand better below :

Well, I have an HTML page containing a form in which an options group
provides two ways to submit content of a file :

- 1st way : base64 data in a textarea field.
- 2nd way : path to local file in a file field

So, to achieve this, when user click on a checkbox of this option group,
a javascript code manages to create and remove appropriated form fields.
And this works well until now.

Here is a test page showing this switching :
--------------------------------------------
http://yohannl.tripod.com/file_form_switcher/file_form_switcher.htm

And here is the source of the page :
------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function addrem(id,op)
{         
        var area = document.getElementById('ftest');
        var elt = document.getElementById(id);        
        
        if (op == 1){ // add field
                if (elt != null){
                        return;}
                if (id == "base64"){
                        elt = document.createElement('textarea');
                        elt.cols = "60";
                        elt.rows = "10";
                        elt.value = "(paste Base64 data here)";}
                else {
                        elt = document.createElement('input');
                        elt.type = "file";}
                elt.id = id;
                elt.name = "file";
                area.appendChild(elt);}
        else { // remove field                
                if (elt != null){
                        area.removeChild(elt);}}}
</script>
</head>
<body>
<h3>File Form Switcher</h3>
<input type="submit" value="Submit">
<form id="ftest" action="/bin/engine.pl" method="post"
enctype="multipart/form-data">
<input type="radio" name="file" value="0" onclick="addrem
('local',0);addrem('base64',1);"> Base64 Data<br>
<input type="radio" name="file" value="1" onclick="addrem
('base64',0);addrem('local',1);"> Local Path<br><br>
</form>
</body>
</html>

So, my question is :
--------------------
Is there a way to achieve this same objective (submit a textarea or a
file field) without any javascript (some browsers will have disabled
javascript support) ?

Knowing the two ways shouldn't be available in the same time (to avoid
user pastes a base64 data in first field AND indicates a local file path
in the second one, both) : one or another according to user choice using
option checkboxes.

Maybe through CSS, don't know. Do you have an idea ?

Posted by Jukka K. Korpela on May 21, 2007, 6:02 am
Please log in for more thread options


Scripsit Asterbing:

> Already posted in comp.lang.javascript but not found any solution :-(

Thanks for the heads-up.

Oh, that was your entire message. The rest is a signature. Well, not quite;
OE just thinks that "--" and not "-- " is a sig separator. Anyway, you seem
to have a _bad_ start.

> because the way to go is included in the possible answer itself by nature

Young Wittgenstein reborn, I presume.

> Well, I have an HTML page containing a form in which an options group
> provides two ways to submit content of a file :
>
> - 1st way : base64 data in a textarea field.
> - 2nd way : path to local file in a file field

Why would anyone use the base64 alternative? Sounds pointless. _Normal_
submission via a textarea might make sense.

Submitting a path to a local file is worse than pointless in web authoring;
it is not just useless, it's also a security threat. How do you expect a web
server to access the user computer's file system, if it has one?

If you wish allow file submissions, use <input type="file" ...>. It has many
complications, but it's the only way. More info:
http://www.cs.tut.fi/~jkorpela/forms/file.html

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Posted by Asterbing on May 21, 2007, 8:39 am
Please log in for more thread options


jkorpela@cs.tut.fi says...
> Why would anyone use the base64 alternative? Sounds pointless. _Normal_
> submission via a textarea might make sense.
>
> Submitting a path to a local file is worse than pointless in web authoring;
> it is not just useless, it's also a security threat. How do you expect a web
> server to access the user computer's file system, if it has one?
>
> If you wish allow file submissions, use <input type="file" ...>. It has many
> complications, but it's the only way. More info:
> http://www.cs.tut.fi/~jkorpela/forms/file.html
>

Sorry, but i's not a reply to my question ;-) I know and haven't any
problem about how to handle both data and file fields values received on
server-side.

My question was about way to manage form on client side : here is a copy
of my first post without the "--" :

Don't know where to ask my question because the way to go is included in
the possible answer itself by nature... You'll understand better below :

Well, I have an HTML page containing a form in which an options group
provides two ways to submit content of a file :

- 1st way : base64 data in a textarea field.
- 2nd way : path to local file in a file field

So, to achieve this, when user click on a checkbox of this option group,
a javascript code manages to create and remove appropriated form fields.
And this works well until now.

Here is a test page showing this switching :
http://yohannl.tripod.com/file_form_switcher/file_form_switcher.htm

And here is the source of the page :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function addrem(id,op)
{         
        var area = document.getElementById('ftest');
        var elt = document.getElementById(id);        
        
        if (op == 1){ // add field
                if (elt != null){
                        return;}
                if (id == "base64"){
                        elt = document.createElement('textarea');
                        elt.cols = "60";
                        elt.rows = "10";
                        elt.value = "(paste Base64 data here)";}
                else {
                        elt = document.createElement('input');
                        elt.type = "file";}
                elt.id = id;
                elt.name = "file";
                area.appendChild(elt);}
        else { // remove field                
                if (elt != null){
                        area.removeChild(elt);}}}
</script>
</head>
<body>
<h3>File Form Switcher</h3>
<input type="submit" value="Submit">
<form id="ftest" action="/bin/engine.pl" method="post"
enctype="multipart/form-data">
<input type="radio" name="file" value="0" onclick="addrem
('local',0);addrem('base64',1);"> Base64 Data<br>
<input type="radio" name="file" value="1" onclick="addrem
('base64',0);addrem('local',1);"> Local Path<br><br>
</form>
</body>
</html>

So, my question is :
Is there a way to achieve this same objective (submit a textarea or a
file field) without any javascript (some browsers will have disabled
javascript support) ?

Knowing the two ways shouldn't be available in the same time (to avoid
user pastes a base64 data in first field AND indicates a local file path
in the second one, both) : one or another according to user choice using
option checkboxes.

Maybe through CSS, don't know. Do you have an idea ?

Posted by Dan on May 21, 2007, 12:45 pm
Please log in for more thread options


> Is there a way to achieve this same objective (submit a textarea or a
> file field) without any javascript (some browsers will have disabled
> javascript support) ?

I've always just included both options on the form in a keep-it-simple-
stupid way, without trying to do anything "clever" with adding and
dropping stuff based on user choices. See for instance my e-mail
format checker:
http://mailformat.dan.info/tools/check.html

> Knowing the two ways shouldn't be available in the same time (to avoid
> user pastes a base64 data in first field AND indicates a local file path
> in the second one, both) : one or another according to user choice using
> option checkboxes.

Users do silly things sometimes, but it's really no big deal; you can
either program your receiving script to ignore one or the other of the
two if they're both given, or else give an error or warning message
notifying the user that their input was inconsistent. You should
always have server-side validity checking anyway, rather than relying
on client-side stuff like Javascript.

--
Dan


Posted by Asterbing on May 21, 2007, 2:48 pm
Please log in for more thread options


dan@tobias.name says...
> I've always just included both options on the form in a keep-it-simple-
> stupid way, without trying to do anything "clever" with adding and
> dropping stuff based on user choices. See for instance my e-mail
> format checker:
> http://mailformat.dan.info/tools/check.html
>

Effectively, seen your form (thanks), but I'm in another case because in
some case (I know, a lot of constraint), the base64 field will be pre-
filled and user will have choice to acdept it or use the file filed to
submit something different : so, I don't think user will think (or even
want to spend any seconds for this in spite of warning) to erase the
textarea content.

>
> Users do silly things sometimes, but it's really no big deal; you can
> either program your receiving script to ignore one or the other of the
> two if they're both given, or else give an error or warning message
> notifying the user that their input was inconsistent. You should
> always have server-side validity checking anyway, rather than relying
> on client-side stuff like Javascript.
>

Yes, but to be totally complete, I have to say I'm not in charge of
server-side and I have to do my best to provide the most filtered as
possible things using client-side possibilities : complex, isn't it ?
;-)

Similar ThreadsPosted
Bug in IE with utf-8 and JavaScript April 11, 2006, 5:26 am
Javascript IP Mailer August 19, 2004, 4:27 pm
problems with JavaScript February 10, 2005, 5:32 pm
Do viewers have JavaScript? March 7, 2005, 9:49 am
508 compliance and Javascript March 15, 2006, 2:17 pm
Forms and javascript March 30, 2006, 7:36 pm
Javascript and Frames August 14, 2006, 11:42 am
Javascript encryptor March 27, 2007, 3:30 pm
Javascript problem? July 10, 2007, 11:59 am
ISO HTML and Javascript November 7, 2007, 2:19 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap