By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

Save as dialog box?

100+
P: 219
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?
Jun 25 '08 #1
Share this Question
Share on Google+
11 Replies


acoder
Expert Mod 15k+
P: 16,027
This is not possible with JavaScript cross-browser. What do you want to save?
Jun 25 '08 #2

vikas251074
100+
P: 198
You can use
Expand|Select|Wrap|Line Numbers
  1. confirm("Do you want to save record?")
It will ask you 'OK' or 'Cancel'.

Thanks and regards,
Vikas
Jun 26 '08 #3

hsriat
Expert 100+
P: 1,654
You can use
Expand|Select|Wrap|Line Numbers
  1. 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'?
Jun 26 '08 #4

acoder
Expert Mod 15k+
P: 16,027
You can use
Expand|Select|Wrap|Line Numbers
  1. 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.
Jun 26 '08 #5

100+
P: 219
Ok, maybe I don't need a save as.

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

Expand|Select|Wrap|Line Numbers
  1. <select name="competency" id="competency" onChange="download_comp(this);return false;">
  2.                   <option selected="selected">Select a Competency</option>
  3.                   <option value="..\test\test.log">Management</option>
  4.                   <option value="..\test\test1.log">Nursing</option>
  5.                   <option value="..\test\test2.log">Staff</option>
  6.                 </select>
  7.  
When the user changes the option in this list, I want the file in the value field to be downloaded to their computer.
Jun 26 '08 #6

acoder
Expert Mod 15k+
P: 16,027
You can use a hidden iframe and set the Content-Disposition header to "force" a download. Here's an example- note: no Ajax involved.
Jun 26 '08 #7

100+
P: 219
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!!
Jun 26 '08 #8

100+
P: 219
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.

Expand|Select|Wrap|Line Numbers
  1. function download_comp(comp){
  2.     var answer = confirm("Would you like to download the selected competency?")
  3.     if(answer){
  4.         competency = comp.value
  5.         oIfrm=document.getElementById('myIFrm')
  6.         oIfrm.src=competency
  7.         alert("Please remember to save the downloaded file to your local machine.  Thanks!")
  8.     }
  9. }
  10.  
Expand|Select|Wrap|Line Numbers
  1. <div>
  2.               <div align="center">
  3.                 <select name="competency" id="competency" onChange="download_comp(this);return false;">
  4.                   <option selected="selected">Select a Competency</option>
  5.                   <option value="..\test\test.log">Management</option>
  6.                   <option value="..\test\test1.log">Nursing</option>
  7.                   <option value="..\test\test2.log">Staff</option>
  8.                 </select>
  9.               </div>
  10.             </div>
  11.  
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?

Expand|Select|Wrap|Line Numbers
  1. function download_perf(perf){
  2. //    performance = perf.value
  3.     alert(perf)
  4.     ifrm=document.getElementById('myIFrm_perf')
  5.     ifrm.src=perf
  6.     alert("Please save the downloaded file to your local machine.  Thanks!")
  7.     alert(ifrm.src)
  8. }
  9.  
Expand|Select|Wrap|Line Numbers
  1.           <td align="center"><input type="radio" name="overall_perf" id="radio93" value="1" OnClick="download_perf('..\\test\testing.xls');return false;"/></td>
  2.  
Jun 26 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Probably the second backslash needs escaping. Can you not use forward slashes for directory separators?
Jun 26 '08 #10

100+
P: 219
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.
Jun 26 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Glad that's sorted.
Jun 26 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.