Click to See Complete Forum and Search --> : how to pop up Save As Window
javahelp
07-09-2003, 12:52 AM
Hi:) everyone,
I am a new member. I need help with javascript.
Does anyone know how to make the SAVE AS WINDOW pop up when the user click on the SAVE button? If you know some source of the code, please let me know.
Thanks
Khalid Ali
07-09-2003, 09:39 PM
the following will open the save as dialogue and its written as it willsave the value in the text field in a text file
<script type="text/javascript">
<!--
function save(){
str = document.forms[0].t1.value;
mydoc = document.open();
mydoc.write(str);
mydoc.execCommand("saveAs",true,".txt");
mydoc.close();
return false;
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<input type="text" name="t1"/>
<input type="button" value="process" onclick="save()"/>
</form>
Note
Works with IE as of my knowledge
javahelp
07-16-2003, 02:08 PM
Hi Khalid,
Thank you very much for your help. When I add radio button group to the page and click submit. I use For Loop, but somehow it gives me an error. I want the value of radio button will display the next page after the user click the submit button.
This code only works for IE, but not for netscrape, right? I did try it out and it does not work.
This is the my code, please help me what did I do wrong
-------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language = "javascript">
function getSelectedButton(buttonGroup){
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup[i].checked) {
return i
}
}
return 0
}
</script>
<script type="text/javascript">
function save(){
str1 = document.forms[0].t1.value + "\n";
str2 = document.forms[0].t2.value + "\n";
var i = getSelectedButton(form.flags);
str3 = document.forms[0].form.flags[i].value;
mydoc = document.open();
mydoc.write(str1);
mydoc.write(str2);
mydoc.write(str3);
mydoc.execCommand("saveAs",true,".txt");
mydoc.close();
return false;
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<p>Location 1: <input type="text" name="t1"></p>
<p>Location 2: <input type="text" name="t2"></p>
<input type="radio" name="flags" value="Pleading" checked>Pleading <br>
<input type="radio" name="flags" value="Letter">Letter<br>
<input type="radio" name="flags" value="Attorney">Attorney<br>
<input type="radio" name="flags" value="Previlege">Previlege<br>
<input type="radio" name="flags" value="Not Relevant">Not Relevant<br>
<p>
<input type="button" value="Submit" onclick="save()"/>
<input type="button" value="Email" onClick="Email()" />
</p>
</form>
</body>
</html>
-----------------------------------------------------------------
By the way, what is the different between :
<script language = "javascript"> and
<script type="text/javascript">
I am looking forward to hearing from you soon
Thanks a bunch
Javahelp
Khalid Ali
07-16-2003, 04:15 PM
language attribute in script tag is depricated....and yes the code will only work in IE
javahelp
07-16-2003, 05:38 PM
Hi Khalid,
Please explain a little more. I got stuck, and don't know how to get it works. Please give more help
Thank you very much
I am waiting for your response
javahelp
Khalid Ali
07-16-2003, 05:53 PM
what does not work please be speciic and post the errror as well
javahelp
07-16-2003, 07:53 PM
Thanks for your response so quickly.
I add couple radiobutton and use For Loop function name getSelectedButton() in order to get the value from the radiobutton when the user click submit. After the user hits submit button, the value from radio button and from text box should display the next page and save as window will appear at the same time. But when I click the submit button, it said error on page.
This is the code:
--------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getSelectedButton(buttonGroup){
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup[i].checked) {
return i
}
}
return 0
}
function save(){
str1 = document.forms[0].t1.value + "\n";
str2 = document.forms[0].t2.value + "\n";
var i = getSelectedButton(flags);
str3 = document.forms[0].flags[i].value;
mydoc = document.open();
mydoc.write(str1);
mydoc.write(str2);
mydoc.write(str3);
mydoc.execCommand("saveAs",true,".txt");
mydoc.close();
return false;
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<p>Location 1: <input type="text" name="t1"></p>
<p>Location 2: <input type="text" name="t2"></p>
<input type="radio" name="flags" value="Pleading" checked>Pleading <br>
<input type="radio" name="flags" value="Letter">Letter<br>
<input type="radio" name="flags" value="Attorney">Attorney<br>
<input type="radio" name="flags" value="Previlege">Previlege<br>
<input type="radio" name="flags" value="Not Relevant">Not Relevant<br>
<p>
<input type="button" value="Submit" onclick="save()"/>
<input type="button" value="Email" onClick="Email()" />
</p>
</form>
</body>
</html>
-----------------------------------------------------------------
Please let me know what is wrong with the code above
Thanks alot
javahelp
Khalid Ali
07-16-2003, 08:34 PM
You did not pass the array of radio buttons
var i = getSelectedButton(flags);
change the above line with this
var i = getSelectedButton(document.forms[0].flags);
javahelp
07-16-2003, 09:22 PM
Thanks a lot Khalid,
I got it right!!!
You are so helpful and kind. You respond my post right away. Do you very expert at javascript. I bet so.
Thanks again
Take care
Khalid Ali
07-17-2003, 12:39 AM
:D
You are welcome
javahelp
07-18-2003, 07:22 PM
Hi Khalid,
Would you please explain a little more what is the different between :
<SCRIPT LANGUAGE = "JAVASCRIPT">
AND
<SCRIPT TYPE = "TEXT/JAVASCRIPT">
Instead use <SCRIPT TYPE = "TEXT/JAVASCRIPT">, I changed to <SCRIPT LANGUAGE = "JAVASCRIPT"> with the code above. It has error, do you know why?
Thanks
Khalid Ali
07-19-2003, 07:50 AM
language attribute is depricated,and is not used anymore.
The correct attribute for this type of decalraion in script element is
type="text/javascript">
Notice the small letters..
Your error has to be from some coding error
Charles
07-19-2003, 08:15 AM
It should be noted that if you use the "language" attribute, and even if you include the "type" attribute, some versions of Netscape will behave in some non-standard ways.
javahelp
07-21-2003, 01:14 AM
Hi,
I would like to use attribue languge rather than attribute type in the code below. Do you know where should I change the code below to work with <script language="javascript"> instead of <script type="text/javascript">
Here is the code:
--------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javacript">
function getSelectedButton(buttonGroup){
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup[i].checked) {
return i
}
}
return 0
}
function save(){
str1 = document.forms[0].t1.value + ",\n";
str2 = document.forms[0].t2.value + ",\n";
var i = getSelectedButton(document.forms[0].flags);
str3 = document.forms[0].flags[i].value;
mydoc = document.open();
mydoc.write(str1);
mydoc.write(str2);
mydoc.write(str3);
mydoc.execCommand("saveAs",true,".txt");
mydoc.close();
return false;
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<p>Location 1: <input type="text" name="t1"></p>
<p>Location 2: <input type="text" name="t2"></p>
<input type="radio" name="flags" value="Pleading" checked>Pleading <br>
<input type="radio" name="flags" value="Letter">Letter<br>
<input type="radio" name="flags" value="Attorney">Attorney<br>
<input type="radio" name="flags" value="Previlege">Previlege<br>
<input type="radio" name="flags" value="Not Relevant">Not Relevant<br>
<p>
<input type="button" value="Submit" onclick="save()"/>
<input type="button" value="Email" onClick="email()" />
</p>
</form>
</body>
</html>
-------------------------------------------
I am really appreciated your help
javahelp
javahelp
07-22-2003, 07:59 PM
Do you know what does the $ sign of the code below mean? Does it effect the code if the $ sign removed? I know that when it starts with "<!-- " and close with " -->", it is comments for the code, right? But I don't understand what is the $ sign there for??
------------------------------------------------------------
<!-- $Begin DocHeader -->
<A Name="hit0"></A><font color=#0000ff size=+1 face="Arial">%%Filename%% (%%HitCount%% hits)</font><HR>
<!-- $End -->
---------------------------------------------------------
Thanks for your help
javahelp
starrwriter
03-14-2004, 01:14 AM
[QUOTE]Originally posted by Khalid Ali
[B]the following will open the save as dialogue and its written as it willsave the value in the text field in a text file
<script type="text/javascript">
<!--
function save(){
str = document.forms[0].t1.value;
mydoc = document.open();
mydoc.write(str);
mydoc.execCommand("saveAs",true,".txt");
mydoc.close();
return false;
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<input type="text" name="t1"/>
<input type="button" value="process" onclick="save()"/>
</form>
That creates output in Unicode .txt files. How would I output correctly formatted HTML code generated from form user input?