Save as dialog box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmorand
    New Member
    • Sep 2007
    • 219

    Save as dialog box?

    I'm trying to get a "Save As" Dialog box to appear when a user changes the option of a select tag. I've looked all over the place, but can't seem to find a way to achieve this. Has anyone done this using javascript?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This is not possible with JavaScript cross-browser. What do you want to save?

    Comment

    • vikas251074
      New Member
      • Dec 2007
      • 198

      #3
      You can use
      Code:
      confirm("Do you want to save record?")
      It will ask you 'OK' or 'Cancel'.

      Thanks and regards,
      Vikas

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by vikas251074
        You can use
        Code:
        confirm("Do you want to save record?")
        It will ask you 'OK' or 'Cancel'.

        Thanks and regards,
        Vikas
        What should he do after the user presses 'OK'?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by vikas251074
          You can use
          Code:
          confirm("Do you want to save record?")
          It will ask you 'OK' or 'Cancel'.
          I can see where you're coming from, but a confirm is not the same as a "Save as..." dialog, though it could be used if you're saving on the server.

          Comment

          • dmorand
            New Member
            • Sep 2007
            • 219

            #6
            Ok, maybe I don't need a save as.

            I have a selection box setup something like this......

            [code=html]
            <select name="competenc y" id="competency " onChange="downl oad_comp(this); return false;">
            <option selected="selec ted">Select a Competency</option>
            <option value="..\test\ test.log">Manag ement</option>
            <option value="..\test\ test1.log">Nurs ing</option>
            <option value="..\test\ test2.log">Staf f</option>
            </select>
            [/code]

            When the user changes the option in this list, I want the file in the value field to be downloaded to their computer.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You can use a hidden iframe and set the Content-Disposition header to "force" a download. Here's an example- note: no Ajax involved.

              Comment

              • dmorand
                New Member
                • Sep 2007
                • 219

                #8
                Originally posted by acoder
                You can use a hidden iframe and set the Content-Disposition header to "force" a download. Here's an example- note: no Ajax involved.
                Let me give that a shot and see what happens, thanks!!

                Comment

                • dmorand
                  New Member
                  • Sep 2007
                  • 219

                  #9
                  How come I have to have the path to my file in the value field, and I can't pass it to a function as an argument?

                  I've got this code setup and it's working properly.

                  [code=javascript]
                  function download_comp(c omp){
                  var answer = confirm("Would you like to download the selected competency?")
                  if(answer){
                  competency = comp.value
                  oIfrm=document. getElementById( 'myIFrm')
                  oIfrm.src=compe tency
                  alert("Please remember to save the downloaded file to your local machine. Thanks!")
                  }
                  }
                  [/code]
                  [code=html]
                  <div>
                  <div align="center">
                  <select name="competenc y" id="competency " onChange="downl oad_comp(this); return false;">
                  <option selected="selec ted">Select a Competency</option>
                  <option value="..\test\ test.log">Manag ement</option>
                  <option value="..\test\ test1.log">Nurs ing</option>
                  <option value="..\test\ test2.log">Staf f</option>
                  </select>
                  </div>
                  </div>
                  [/code]

                  When I try to pass the path to download as an argument, I use alert to see what the value looks like and the path is all jumbled looking, not sure why it's doing that, but I'm assuming I need to convert the path or something, any ideas?

                  [code=javascript]
                  function download_perf(p erf){
                  // performance = perf.value
                  alert(perf)
                  ifrm=document.g etElementById(' myIFrm_perf')
                  ifrm.src=perf
                  alert("Please save the downloaded file to your local machine. Thanks!")
                  alert(ifrm.src)
                  }
                  [/code]

                  [code=html]
                  <td align="center"> <input type="radio" name="overall_p erf" id="radio93" value="1" OnClick="downlo ad_perf('..\\te st\testing.xls' );return false;"/></td>
                  [/code]

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Probably the second backslash needs escaping. Can you not use forward slashes for directory separators?

                    Comment

                    • dmorand
                      New Member
                      • Sep 2007
                      • 219

                      #11
                      Originally posted by acoder
                      Probably the second backslash needs escaping. Can you not use forward slashes for directory separators?
                      Wow that's all it was. I should have realized I needed to escape the slashes. I used forward slashes instead.

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Glad that's sorted.

                        Comment

                        Working...