How to do the same without javascript ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Asterbing

    How to do the same without javascript ?

    Already posted in comp.lang.javas cript 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 :
    --------------------------------------------


    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.getEle mentById('ftest ');
    var elt = document.getEle mentById(id);

    if (op == 1){ // add field
    if (elt != null){
    return;}
    if (id == "base64"){
    elt = document.create Element('textar ea');
    elt.cols = "60";
    elt.rows = "10";
    elt.value = "(paste Base64 data here)";}
    else {
    elt = document.create Element('input' );
    elt.type = "file";}
    elt.id = id;
    elt.name = "file";
    area.appendChil d(elt);}
    else { // remove field
    if (elt != null){
    area.removeChil d(elt);}}}
    </script>
    </head>
    <body>
    <h3>File Form Switcher</h3>
    <input type="submit" value="Submit">
    <form id="ftest" action="/bin/engine.pl" method="post"
    enctype="multip art/form-data">
    <input type="radio" name="file" value="0" onclick="addrem
    ('local',0);add rem('base64',1) ;"Base64 Data<br>
    <input type="radio" name="file" value="1" onclick="addrem
    ('base64',0);ad drem('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 ?
  • Jukka K. Korpela

    #2
    Re: How to do the same without javascript ?

    Scripsit Asterbing:
    Already posted in comp.lang.javas cript 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:


    --
    Jukka K. Korpela ("Yucca")


    Comment

    • Asterbing

      #3
      Re: How to do the same without javascript ?

      In article <17e4i.167146$C W1.82233@reader 1.news.saunalah ti.fi>,
      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:

      >
      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 :


      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.getEle mentById('ftest ');
      var elt = document.getEle mentById(id);

      if (op == 1){ // add field
      if (elt != null){
      return;}
      if (id == "base64"){
      elt = document.create Element('textar ea');
      elt.cols = "60";
      elt.rows = "10";
      elt.value = "(paste Base64 data here)";}
      else {
      elt = document.create Element('input' );
      elt.type = "file";}
      elt.id = id;
      elt.name = "file";
      area.appendChil d(elt);}
      else { // remove field
      if (elt != null){
      area.removeChil d(elt);}}}
      </script>
      </head>
      <body>
      <h3>File Form Switcher</h3>
      <input type="submit" value="Submit">
      <form id="ftest" action="/bin/engine.pl" method="post"
      enctype="multip art/form-data">
      <input type="radio" name="file" value="0" onclick="addrem
      ('local',0);add rem('base64',1) ;"Base64 Data<br>
      <input type="radio" name="file" value="1" onclick="addrem
      ('base64',0);ad drem('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 ?

      Comment

      • Dan

        #4
        Re: How to do the same without javascript ?

        On May 21, 8:39 am, Asterbing <n...@thanks.co mwrote:
        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:
        Tool to check the compliance of an e-mail message with standards, guidelines, and good practices. Part of Dan's Mail Format Site, a site about the formatting of e-mail.

        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

        Comment

        • Jukka K. Korpela

          #5
          Re: How to do the same without javascript ?

          Scripsit Asterbing:
          Sorry, but i's not a reply to my question ;-)
          This isn't a helpdesk, and this is a discussion group about HTML authoring
          for the World Wide Web.
          My question was about way to manage form on client side
          That's not something you do in HTML.

          If you really know what you are doing server-side, then you don't have any
          problem as long as you simply include two alternatives - a form field and a
          textarea - into the HTML form. If you wish to get help with _creating_ some
          problems client-side, you need to ask for help elsewhere.
          here is a copy of my first post without the "--" :
          Are you trying to get plonked or what?

          --
          Jukka K. Korpela ("Yucca")


          Comment

          • Asterbing

            #6
            Re: How to do the same without javascript ?

            In article <1179765958.929 196.236840@z28g 2000prd.googleg roups.com>,
            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:
            Tool to check the compliance of an e-mail message with standards, guidelines, and good practices. Part of Dan's Mail Format Site, a site about the formatting of e-mail.

            >
            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 ?
            ;-)

            Comment

            • Asterbing

              #7
              Re: How to do the same without javascript ?

              In article <Gik4i.167385$_ Q5.93463@reader 1.news.saunalah ti.fi>,
              jkorpela@cs.tut .fi says...
              This isn't a helpdesk, and this is a discussion group about HTML authoring
              for the World Wide Web.
              >
              HTML and all arounbd, I guess
              My question was about way to manage form on client side
              >
              That's not something you do in HTML.
              I don't know the reply and this because of that I'm asking the question
              ;-)
              If you really know what you are doing server-side, then you don't have any
              problem as long as you simply include two alternatives - a form field and a
              textarea - into the HTML form.
              I'm not in charge of the server-side in the project and this is the
              corner of the problem : I have to solve this on client-side.
              If you wish to get help with _creating_ some
              problems client-side, you need to ask for help elsewhere.
              >
              Just indicate me the right newsgroup and I'll go without delay ;-) The
              probvlem is that it depend of the way of solution : according to your
              opinion, should I put my question in a group about CSS, javascript (I
              want to strip-out js), HTML (maybe alt.html ?), general authoring...
              Where ?

              Comment

              • Jukka K. Korpela

                #8
                Re: How to do the same without javascript ?

                Scripsit Asterbing:
                >This isn't a helpdesk, and this is a discussion group about HTML
                >authoring for the World Wide Web.
                >
                HTML and all arounbd, I guess
                You guessed wrong. How about checking some facts? The newsgroup descriptions
                aren't really top secret documents.
                I'm not in charge of the server-side in the project and this is the
                corner of the problem : I have to solve this on client-side.
                So did you previously lie when you wrote: "I know and haven't any
                problem about how to handle both data and file fields values received on
                server-side"? If there are no problems there, then you don't have to solve
                "this" on client-side.

                Besides, if you had to solve this on client-side, then there is no solution
                for you. Just because you need to invent a perpetuum mobile doesn't make it
                possible.
                Just indicate me the right newsgroup and I'll go without delay ;-)
                This isn't a helpdesk for finding a group. So far, you conduct has been
                disruptive, so I don't suggest any group before you have thought about the
                issue, considered the responses you have got and studied some Usenet
                behavior (or "netiquette ") guidelines.

                --
                Jukka K. Korpela ("Yucca")


                Comment

                • Beauregard T. Shagnasty

                  #9
                  Re: How to do the same without javascript ?

                  Asterbing wrote:
                  I'm not in charge of the server-side in the project and this is the
                  corner of the problem : I have to solve this on client-side.
                  For some tasks, you need to collaborate. Surely your server-side people
                  realize this.

                  --
                  -bts
                  -Motorcycles defy gravity; cars just suck

                  Comment

                  • Asterbing

                    #10
                    Re: How to do the same without javascript ?

                    In article <Qpn4i.167508$c P7.121022@reade r1.news.saunala hti.fi>,
                    jkorpela@cs.tut .fi says...
                    Scripsit Asterbing:
                    >
                    You guessed wrong. How about checking some facts? The newsgroup descriptions
                    aren't really top secret documents.
                    Just some ten thousands of ng to check, as you say.
                    So did you previously lie when you wrote: "I know and haven't any
                    problem about how to handle both data and file fields values received on
                    server-side"? If there are no problems there, then you don't have to solve
                    "this" on client-side.
                    >
                    I have not any problem in server-side because of two things : 1) it's
                    not my job 2) the ones who work on this already handle the base64 case
                    and the file field one. My job is just to provide one or another, not
                    both.
                    Besides, if you had to solve this on client-side, then there is no solution
                    for you. Just because you need to invent a perpetuum mobile doesn't make it
                    possible.
                    >
                    A little bit restrictive reply, isn't it. If you don't have any positive
                    element to transmit here, why reply ? Are you in charge of something
                    special in this ng ?
                    Just indicate me the right newsgroup and I'll go without delay ;-)
                    >
                    This isn't a helpdesk for finding a group. So far, you conduct has been
                    disruptive, so I don't suggest any group before you have thought about the
                    issue, considered the responses you have got and studied some Usenet
                    behavior (or "netiquette ") guidelines.
                    >
                    And it's not the Yucca's group !

                    Comment

                    • Asterbing

                      #11
                      Re: How to do the same without javascript ?

                      In article <QEn4i.26034$p4 7.10373@bgtnsc0 4-news.ops.worldn et.att.net>,
                      a.nony.mous@exa mple.invalid says...
                      Asterbing wrote:
                      >
                      I'm not in charge of the server-side in the project and this is the
                      corner of the problem : I have to solve this on client-side.
                      >
                      For some tasks, you need to collaborate. Surely your server-side people
                      realize this.
                      >
                      >
                      Yes, you're right, but it's a matter of deadline : even if we'll succeed
                      to collaborate, the fact is that we're not "synchro" just now.

                      Comment

                      • rf

                        #12
                        Re: How to do the same without javascript ?

                        "Asterbing" <no@thanks.comw rote in message
                        news:MPG.20bce0 84373a01dc98992 9@news.tiscali. fr...
                        In article <QEn4i.26034$p4 7.10373@bgtnsc0 4-news.ops.worldn et.att.net>,
                        a.nony.mous@exa mple.invalid says...
                        >Asterbing wrote:
                        >>
                        I'm not in charge of the server-side in the project and this is the
                        corner of the problem : I have to solve this on client-side.
                        >>
                        >For some tasks, you need to collaborate. Surely your server-side people
                        >realize this.
                        >>
                        >>
                        >
                        Yes, you're right, but it's a matter of deadline : even if we'll succeed
                        to collaborate, the fact is that we're not "synchro" just now.
                        Let me see...

                        You have a textarea which may or may not contain data.

                        You have a <input type="file"whic h may or may not contain a file name,
                        which will be uploaded.

                        You want one, and only one, of them to be sent to the server. Correct?

                        If, as you state, javascript is not available then you do not have any
                        control over this. If both input fields are "successful l" then both will be
                        sent to the server. That is how browsers work. End of story. Go over to the
                        specifications and read up on how input fields become "successful l", and how
                        they are sent to the server when they are.

                        As Beauregard implies, it is time to tell your supervisor/boss that this
                        simply can - not - be - done. You will NOT solve this client side.

                        Have it fixed it server side.


                        --
                        Richard.


                        Comment

                        • Beauregard T. Shagnasty

                          #13
                          Re: How to do the same without javascript ?

                          rf wrote:
                          As Beauregard implies, it is time to tell your supervisor/boss that this
                          simply can - not - be - done. You will NOT solve this client side.
                          Hmmm. Let's think about this a moment or so...

                          <form>
                          [HTML-by-JavaScript]
                          <noscript>
                          <p>GO AWAY! You can't use this form, you silly person!</p>
                          </noscript>
                          </form>

                          There ya go. Problem solved. To hell with the 10% who won't be able to
                          use it.

                          --
                          -bts
                          -posting complete; remove tongue from cheek

                          Comment

                          • Jonathan N. Little

                            #14
                            Re: How to do the same without javascript ?

                            Beauregard T. Shagnasty wrote:
                            rf wrote:
                            >
                            >As Beauregard implies, it is time to tell your supervisor/boss that this
                            >simply can - not - be - done. You will NOT solve this client side.
                            >
                            Hmmm. Let's think about this a moment or so...
                            >
                            <form>
                            [HTML-by-JavaScript]
                            <noscript>
                            <p>GO AWAY! You can't use this form, you silly person!</p>
                            </noscript>
                            </form>
                            LOL!

                            To OP: In case you haven't gotten the message here is the mantra "Never
                            rely on client-side for 'mission critical' operations, it is the role of
                            server-side". Now repeat 100 times or until you "get it". If it is your
                            boss that insists, then print this out and have him recite the mantra
                            until he "gets it".

                            --
                            Take care,

                            Jonathan
                            -------------------
                            LITTLE WORKS STUDIO
                            http://www.LittleWorks Studio.com

                            Comment

                            • Darin McGrew

                              #15
                              Re: How to do the same without javascript ?

                              rf <rf@invalid.com wrote:
                              You have a textarea which may or may not contain data.
                              >
                              You have a <input type="file"whic h may or may not contain a file name,
                              which will be uploaded.
                              >
                              You want one, and only one, of them to be sent to the server. Correct?
                              >
                              If, as you state, javascript is not available then you do not have any
                              control over this. If both input fields are "successful l" then both will be
                              sent to the server. That is how browsers work. End of story. Go over to the
                              specifications and read up on how input fields become "successful l", and how
                              they are sent to the server when they are.
                              >
                              As Beauregard implies, it is time to tell your supervisor/boss that this
                              simply can - not - be - done. You will NOT solve this client side.
                              Maybe I missed something. Is there a reason the OP can't have two separate
                              forms, one with the textarea and one with the <input type="file">? Naive
                              users can submit only one form's data at a time, regardless of whether
                              JavaScript is available/enabled.

                              Malicious users can still submit whatever they like to the server-side
                              program, but they could do that before.
                              --
                              Darin McGrew, mcgrew@stanford alumni.org, http://www.rahul.net/mcgrew/
                              Web Design Group, darin@htmlhelp. com, http://www.HTMLHelp.com/

                              "Advice is what you ask for when you know the answer but wish you didn't."

                              Comment

                              Working...