Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: How to convert file download from option to checkbox


Message #1 by "Derek VR" <davr2000@h...> on Wed, 29 Jan 2003 18:01:44
This works great... in IE. I'm wondering what differences in the Netscape 
DOM might be causing a "Bad Request: Your browser sent a request that 
this server could not understand." error.

Thanks again for your help,
Derek

> The references you have to the checkboxes are incorrect.  Files is an 
a> rray of checkboxes, so you don't need to add .checkbox to the path.  
It 
s> hould just be form.Files[i].  Try this:

> <html>
<> head>
<> title>Untitled Document</title>
<> meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1"> 
<> script language="javascript" type="text/javascript">
<> !--
f> unction download() {
 >    var form = document.forms[0];
 >    var numCheckboxes = form.Files.length;
 >    
 >    for (var i=0; i<numCheckboxes; i++) {
	> 		var currentCheckbox = form.Files[i];
 >        if (currentCheckbox.checked == true) {
 >  alert(currentCheckbox.value);
 >            window.open(currentCheckbox.value,"new"+i,"");
 >        }
 >    }
}> 
/> / -->
<> /script>
<> /head>

> <body>
 >   <form method="post" onsubmit="download(); return false">
 >  <p>Files to download&nbsp;&nbsp; 
 >    <input type="checkbox" name="Files" 
v> 
alue="http://download.microsoft.com/download/winscript56/Install/5.6/W9XN
T> 4
m> e/en-us/scr56en.exe"><br><br>
 >    <input type="checkbox" name="Files" 
v> 
alue="http://download.microsoft.com/download/winscript56/Install/5.6/W9XN
T> 4
m> e/en-us/scr56en.exe">
 >  </p>
 >  <p><br>
 >    <br>
 >    <input type="submit" value="Download selected file(s)">
 >    <input type="reset" value="clear">
 >  </p>
<> /form>
<> /body>
<> /html>

> </HTML>

> 
>>  Hi,

> > I working on converting the script/form below from an option list to 
c> > heckboxes. When submitted, the form opens a popup and then a 
s> ubsequent 
f> > ile download prompt:

> > <html>
<> > head>
<> > title>downer.htm</title>
<> > script language="javascript" type="text/javascript">
<> > !--
f> > unction download() {
 > >    var form = document.forms[0];
 > >    for (var i=0; i<form.Files.length; i++) {
 > >        if (form.Files.options[i].selected) {
 > >  alert(form.Files.options[i].text);
 > >            window.open(form.Files.options[i].value,"new"+i,"");
 > >        }
 > >    }
}> > 
/> > / -->
<> > /script>
<> > /head>
<> > body>
 > >   <form method="post" onsubmit="download()">
 > >   <b>microsoft Windows Script 5.6 downloads:</b>
 > >   <br>
 > >   <select name="Files" size="2" multiple>
 > >      <option
v> > 
a> 
lue="http://download.microsoft.com/download/winscript56/Install/5.6/NT5/
E> > N
-> > us/scripten.exe">english Download for Win 2000
 > >      <option
v> > 
a> 
lue="http://download.microsoft.com/download/winscript56/Install/5.6/W9XN
T> > 4
m> > e/en-us/scr56en.exe">english Download for Win 98, Me, NT 4.0
 > >   </select>
 > >   <br>
 > >   <input type="submit" value="Download selected file(s)">
 > >   <input type="reset" value="clear">
 > >   </form>
<> > /body>
<> > /html>

> > 
S> > o far, I've tried this:

> > <html>
<> > head>
<> > title>Untitled Document</title>
<> > meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
<> > script language="javascript" type="text/javascript">
<> > !--
f> > unction download() {
 > >    var form = document.forms[0];
 > >    for (var i=0; i<form.Files.length; i++) {
 > >        if (form.Files.checkbox[i].checked == true) {
 > >  alert(form.Files.checkbox[i].text);
 > >            window.open(form.Files.checkbox[i].value,"new"+i,"");
 > >        }
 > >    }
}> > 
/> > / -->
<> > /script>
<> > /head>

> > <body>
 > >   <form method="post" onsubmit="download()">
 > >  <p>Files to download&nbsp;&nbsp; 
 > >    <input type="checkbox" name="Files" 
v> > 
a> 
lue="http://download.microsoft.com/download/winscript56/Install/5.6/W9XN
T> > 4
m> > e/en-us/scr56en.exe"><br><br>
 > >    <input type="checkbox" name="Files" 
v> > 
a> 
lue="http://download.microsoft.com/download/winscript56/Install/5.6/W9XN
T> > 4
m> > e/en-us/scr56en.exe">
 > >  </p>
 > >  <p><br>
 > >    <br>
 > >    <input type="submit" value="Download selected file(s)">
 > >    <input type="reset" value="clear">
 > >  </p>
<> > /form>
<> > /body>
<> > /html>

> > 
T> > hanks for your help,
D> > erek

  Return to Index