473,414 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Does this possible without javascript ?

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_...m_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;

if (op == 1){ // add field
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
elt = document.getElementById(id);
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 without any javascript
code (for browsers with disabled javascript support of course) ?

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.

Do you have an idea ?
May 20 '07 #1
9 1576
On May 20, 10:06 am, Asterbing <n...@thanks.comwrote:
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.
<snip js code>
So, my question is :
--------------------
Is there a way to achieve this same objective without any javascript
code (for browsers with disabled javascript support of course) ?
I like your attitude
Do you have an idea ?
Fall back to the file input field for non-js enabled browsers.
When js is enabled, write out the required parts in a script block
with document.writeln()

<script type="text/javascript">
document.writeln('<input type="radio" name="file" value="0"
onclick="addrem(\'local\',0);addrem(\'base64\',1); ">Base64 Data<br>');
//....
</script>
<noscript>
<input type="file" id="some-data"/>
</noscript>
May 20 '07 #2
In article <11**********************@y18g2000prd.googlegroups .com>,
sk*******@gmail.com says...
Fall back to the file input field for non-js enabled browsers.
When js is enabled, write out the required parts in a script block
with document.writeln()

<script type="text/javascript">
document.writeln('<input type="radio" name="file" value="0"
onclick="addrem(\'local\',0);addrem(\'base64\',1); ">Base64 Data<br>');
//....
</script>
<noscript>
<input type="file" id="some-data"/>
</noscript>
Hum, thanks Skye, but it means user w/o javascript will have no choice
between base64 and file submitting...

Is there any way to preserve the choice even w/o javascript ?

Maybe something going through CSS ? Don't know...
May 20 '07 #3

"Asterbing" <no@thanks.comwrote in message
news:MP************************@news.tiscali.fr...
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.
Not for me. I get a js error from this page. Also, when I click more than
once in a row on either
radio button, I get multiple testfields or file inputs.
Here is a test page showing this switching :
--------------------------------------------
http://yohannl.tripod.com/file_form_...m_switcher.htm

May 21 '07 #4
In article <Bv64i.202328$aG1.89742@pd7urf3no>, no****@someisp.ca says...
Not for me. I get a js error from this page. Also, when I click more than
once in a row on either
radio button, I get multiple testfields or file inputs.
OK, but this test page is just a piece extracted from the real page
which has been well tested under IE, Netscape, FireFox, Mozilla and
Opera for Windows. So, I'll check against the real page if I get any
error if you tell me what's your own context : what browser ? what
version ? what operating system do you use ?

Also, do you have an idea for the question of this topic : how to
achieve the same without javascript ?
May 21 '07 #5
In article <Bv64i.202328$aG1.89742@pd7urf3no>, no****@someisp.ca says...
Also, when I click more than
once in a row on either
radio button, I get multiple testfields or file inputs.
Corrected. Below is new javascript code (updated in online test page
too). However, the question remains the same :

How to do this same choice without javascript ?

--
<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>
--
May 21 '07 #6

"Asterbing" <no@thanks.comwrote in message
news:MP************************@news.tiscali.fr...
In article <Bv64i.202328$aG1.89742@pd7urf3no>, no****@someisp.ca says...
Also, when I click more than
once in a row on either
radio button, I get multiple testfields or file inputs.

Corrected. Below is new javascript code (updated in online test page
too). However, the question remains the same :

How to do this same choice without javascript ?

I think you would need to display both the textfield and the file input when
the user has not enabled javascript. Preventing a user from submitting both
would not be possible; you would need to inform the user that one and only
one method can be used at a time, and do server side validation to enforce
that rule.
May 21 '07 #7
On May 20, 2:44 pm, Asterbing <n...@thanks.comwrote:
In article <1179683047.021329.230...@y18g2000prd.googlegroups .com>,skye.s...@gmail.com says...
Fall back to the file input field for non-js enabled browsers.
When js is enabled, write out the required parts in a script block
with document.writeln()
<script type="text/javascript">
document.writeln('<input type="radio" name="file" value="0"
onclick="addrem(\'local\',0);addrem(\'base64\',1); ">Base64 Data<br>');
//....
</script>
<noscript>
<input type="file" id="some-data"/>
</noscript>

Hum, thanksSkye, but it means user w/o javascript will have no choice
between base64 and file submitting...

Is there any way to preserve the choice even w/o javascript ?
In the cases where there is no js, just show both options/radio
buttons.
Although if there is no js, you wont be able to base64 encode the
text.

That aside, If you really, really, want to show just one at a time,
use the noscript/javascript element technique
to generate a form with, say, the file upload field, and a submit
button that will submit the form to the server so it can generate the
alternate upload form, if the user wants to use that method.

As for CSS, maybe some hover, display:block type tactics will work.

May 21 '07 #8
In article <Pwk4i.204763$aG1.107932@pd7urf3no>, no****@someisp.ca
says...
I think you would need to display both the textfield and the file input when
the user has not enabled javascript. Preventing a user from submitting both
would not be possible; you would need to inform the user that one and only
one method can be used at a time, and do server side validation to enforce
that rule.

Yes, it's what I suspected and the reason why of my question here... In
case someone else would has another way in mind... My problem is that
I'm not the one in charge of the server-side, but I have to adjust
things on client-side :-(
May 21 '07 #9
In article <11*********************@y2g2000prf.googlegroups.c om>,
sk*******@gmail.com says...
In the cases where there is no js, just show both options/radio
buttons.
Although if there is no js, you wont be able to base64 encode the
text.
Oh, no, don't worry about this, this base64 field is provided because in
the framework this form arrives, user may have directly a base64 data
block to paste in my textarea field ; not any encoding to do by code
here.
>
That aside, If you really, really, want to show just one at a time,
use the noscript/javascript element technique
to generate a form with, say, the file upload field, and a submit
button that will submit the form to the server so it can generate the
alternate upload form, if the user wants to use that method.
Good idea, maybe ! I keep it in mind ! Also, It push me another idea :
just provide two forms on screen ; so, even if user fill-in bot textarea
and file field, there will be not in the same form...
>
As for CSS, maybe some hover, display:block type tactics will work.
A little bit more confuse for me, but I've posted my question in
comp.infosystems.www.authoring.html : maybe some idea will come using
this way.
May 21 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Andrea | last post by:
Hi everyone, I am in the process of learning javascript and have a question on location.href. Does javascript always require the <script language = "javascript"> (or script...
3
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
7
by: Andy | last post by:
Hi, I have a complicated question that I'm hoping someone can help me out with. I have a webpage that contains a plug-in. This plug-in can communicate/pass data with the webpage that contains it...
6
by: Paul Lautman | last post by:
Normally I ask why things DON'T work!! However, according to what I have read at http://subsimple.com/bookmarklets/rules.asp the bookmarklet: javascript:q = prompt("Enter destination or leave...
18
by: damezumari | last post by:
I would like to know how many of the visitors to my site has js enabled and how many has it turned off. I haven't found a simple solution searching Google groups so I suggest the following using...
14
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does K = parseInt('09') set K to 0? ----------------------------------------------------------------------- ...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
23
by: mosesdinakaran | last post by:
Hi All, I need a small clarification in submitting the forms, Ur suggestions please. In a page I have two form and also two submit butons. (ie)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.