princehyderabad
asked on
Logic Needed
hi
I need some good logic to work on my solutions. Actualy there mutliple questions to be solved here.
My output should look like this:
========================== ==
() HTTP
() HTTPS
() FTP
File size Download
abc 10mb <image>
123 15mb <image>
xyz 20mb <image>
========================== =
Three radio buttons to select kind of download they want. <image> is the actual link which downloads. User can click on each download <image> which he need to download and save to his disk. My issues now:
Question #1: when user click on download <image> how can I get the value of radio button he selected above ?
Question # 2: How can I combine my below code to have "File, Size, Download" in one table or alteast look like one table to user.
To get "File" and "size" I'm using following code:
.......................... .....
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td></tr> ");
path.add(rs.getString(10)+ rsgetStrin g(6));
if (rs.next()) {
out.print("<tr><td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td></tr> ");
path.add(rs.getString(10)+ rsgetStrin g(6));
}
}
<!-- And I will get Download links using this code -->
ArrayList a = path;
String s = null;
for (int i=0; i<a.size(); i++){
.......................... .......... .....
.......................... .......... .......
while ((s=in.readLine()) != null)
{
out.print("<td><a href='???How to get radio button value user selected here?????"+s+"><image></a> </td>");
}
Thanks for your time !!
I need some good logic to work on my solutions. Actualy there mutliple questions to be solved here.
My output should look like this:
==========================
() HTTP
() HTTPS
() FTP
File size Download
abc 10mb <image>
123 15mb <image>
xyz 20mb <image>
==========================
Three radio buttons to select kind of download they want. <image> is the actual link which downloads. User can click on each download <image> which he need to download and save to his disk. My issues now:
Question #1: when user click on download <image> how can I get the value of radio button he selected above ?
Question # 2: How can I combine my below code to have "File, Size, Download" in one table or alteast look like one table to user.
To get "File" and "size" I'm using following code:
..........................
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
path.add(rs.getString(10)+
if (rs.next()) {
out.print("<tr><td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
path.add(rs.getString(10)+
}
}
<!-- And I will get Download links using this code -->
ArrayList a = path;
String s = null;
for (int i=0; i<a.size(); i++){
..........................
..........................
while ((s=in.readLine()) != null)
{
out.print("<td><a href='???How to get radio button value user selected here?????"+s+"><image></a>
}
Thanks for your time !!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
your q2 was not clear enough to me..
you are already putting your size and file in tr td..
>> out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td></tr> ");
which will put them in one table..
so you already have the code....
you are already putting your size and file in tr td..
>> out.print("<td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
which will put them in one table..
so you already have the code....
ASKER
well the problem is setting correct <tr><td> etc., with my above code the output is in this way.
File Size Download
-------------------------- ---------- ------
File1 size1
File2 size2 File3 size3
<downloadImage1>
<downloadImage2>
<downloadImage3>
-------------------------- ---------- ------
I guess it should be like this:
File Size Download
-------------------------- ---------- ------
File1 size1 <downloadImage1>
File2 size2 <downloadImage2>
File3 size3 <downloadImage3>
-------------------------- ---------- ------
File Size Download
--------------------------
File1 size1
File2 size2 File3 size3
<downloadImage1>
<downloadImage2>
<downloadImage3>
--------------------------
I guess it should be like this:
File Size Download
--------------------------
File1 size1 <downloadImage1>
File2 size2 <downloadImage2>
File3 size3 <downloadImage3>
--------------------------
ASKER
With this code I'm getting output as:
File Size Download
-------------------------- ---------- ------
File1 size1
File2 size2
File3 size3
<downloadImage1>
<downloadImage2>
<downloadImage3>
-------------------------- ---------- ------
----------code------------ ---------- -----
out.print(<tr>);
while (rs.next()) {
out.print("<td>..</td>");
out.print("<td>..</td></tr >");
if (rs.next()) {
out.print("<tr><td>..</td> ");
out.print("<td>..</td></tr >");
}
}
.......................... .........
for (int i=0; i<a.size(); i++){
.......................... .......... .....
.......................... .......... .......
while ((s=in.readLine()) != null)
{
out.print("<td>...Download Image....</td>");
}
out.print(</tr>);
File Size Download
--------------------------
File1 size1
File2 size2
File3 size3
<downloadImage1>
<downloadImage2>
<downloadImage3>
--------------------------
----------code------------
out.print(<tr>);
while (rs.next()) {
out.print("<td>..</td>");
out.print("<td>..</td></tr
if (rs.next()) {
out.print("<tr><td>..</td>
out.print("<td>..</td></tr
}
}
..........................
for (int i=0; i<a.size(); i++){
..........................
..........................
while ((s=in.readLine()) != null)
{
out.print("<td>...Download
}
out.print(</tr>);
okay now I see what you are saying...
well there are two ways for doing so...
1. make one large table and insert both your tables inside it..
i.e.
<table>
<tr>
<td>
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td></tr> ");
path.add(rs.getString(10)+ rsgetStrin g(6));
if (rs.next()) {
out.print("<tr><td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td></tr> ");
path.add(rs.getString(10)+ rsgetStrin g(6));
}
}
//all your code for getting file and size
</td>
<td>
ArrayList a = path;
String s = null;
for (int i=0; i<a.size(); i++){
.......................... .......... .....
.......................... .......... .......
while ((s=in.readLine()) != null)
{
out.print("<td><a href='???How to get radio button value user selected here?????"+s+"><image></a> </td>");
}
//all your code for paths
</td>
</tr>
<table>
another way is to create the path along with size and file name...this 2nd approach depends on your code if you have your path ready at the time you are making your table... then you can create another td and put the path out there
well there are two ways for doing so...
1. make one large table and insert both your tables inside it..
i.e.
<table>
<tr>
<td>
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
path.add(rs.getString(10)+
if (rs.next()) {
out.print("<tr><td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
path.add(rs.getString(10)+
}
}
//all your code for getting file and size
</td>
<td>
ArrayList a = path;
String s = null;
for (int i=0; i<a.size(); i++){
..........................
..........................
while ((s=in.readLine()) != null)
{
out.print("<td><a href='???How to get radio button value user selected here?????"+s+"><image></a>
}
//all your code for paths
</td>
</tr>
<table>
another way is to create the path along with size and file name...this 2nd approach depends on your code if you have your path ready at the time you are making your table... then you can create another td and put the path out there
ASKER
Help me out a little. I'm trying same but hving hard time.
<table>
<tr> <td>File</td>
<td>Size</td>
<td>Download</td>
</tr>
<tr>
from here U guide ........
<table>
<tr> <td>File</td>
<td>Size</td>
<td>Download</td>
</tr>
<tr>
from here U guide ........
ASKER
MY Download images are not in separate table. Just to clarify your point. U said to take BIG table and have two table in it. I dont hv 2 table it was only 1 table I was using.
assuming that the path is being obtained from the result only.. this is how your table structure should be looking..
out.print("<table><tr><td> File</td>< td>Size</t d><td>Path </td>");
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<tr>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(6)+" </td>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS tring(8)+" </td>");
out.print(<td valign='top' class='tdnormal' ><a href=javascript:RadioButto n("+rs.get String(10) +rsgetStri ng(6)+")>< IMG></td>" );
//here I have assumed that your 6 & 8 makes the path for you.. if thats not the case then you might have to do some processing before printing out this last line...
out.print("</tr>");
}
out.print("</table>");
out.print("<table><tr><td>
ArrayList path = new ArrayList();
while (rs.next()) {
out.print("<tr>");
out.print("<td valign='top' class='tdnormal'>"+rs.getS
out.print("<td valign='top' class='tdnormal'>"+rs.getS
out.print(<td valign='top' class='tdnormal' ><a href=javascript:RadioButto
//here I have assumed that your 6 & 8 makes the path for you.. if thats not the case then you might have to do some processing before printing out this last line...
out.print("</tr>");
}
out.print("</table>");
ASKER
Well I used my logic in table I got to the point. But need fnishing as width are not common across.
But you JS is not working.
I mean when I take the mouse I can see the status bar: javascript:RadioSelecttion (it/test/d ownload.ex e)
When I click nothting working ??
But you JS is not working.
I mean when I take the mouse I can see the status bar: javascript:RadioSelecttion
When I click nothting working ??
we will need to put "" around it...
is should come as "javascript:RadioSelecttio n(it/test/ download.e xe);"
also just to check put alerts in your javascript function to see if its getting invoked or not..
is should come as "javascript:RadioSelecttio
also just to check put alerts in your javascript function to see if its getting invoked or not..
ASKER
Yes I tried using alert msg. Its not working.
My JSP code:
out.print("<td><a href='javascript:RadioSele ction("+s+ ")'><image ></a></td> </tr>");
My JSP code:
out.print("<td><a href='javascript:RadioSele
ASKER
on Status Bar I can see: javascript:RadioSelection( it/test/do wnload.exe )
Error on Mozilla Browser: Missing ( arugment list
Error on IE: "it" is undefined
Error on Mozilla Browser: Missing ( arugment list
Error on IE: "it" is undefined
yup we need to put quotes around it it should be
javascript:RadioSelection( 'it/test/d ownload.ex e')
in your jsp change the line
out.print("<td><a href='javascript:RadioSele ction("+s+ ")'><image ></a></td> </tr>");
to have quotes in it
out.print("<td><a href='javascript:RadioSele ction('"+s +"')'><ima ge></a></t d></tr>");
javascript:RadioSelection(
in your jsp change the line
out.print("<td><a href='javascript:RadioSele
to have quotes in it
out.print("<td><a href='javascript:RadioSele
ASKER
Still didnt worked !!
When I take mouse over I can see on status bar only this:
javascript:RadioSelection(
When I look into the source code it was like this:
<a href='javascript:RadioSele ction('it/ test/downl oad.exe')' >
When I take mouse over I can see on status bar only this:
javascript:RadioSelection(
When I look into the source code it was like this:
<a href='javascript:RadioSele
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay now I made it look the way U wanted on status bar I can see this:
javascript:RadioSelection( 'it/test/d ownload.ex e');
But when I click nothing is working. I check the JavaScript console to find error and I got this error:
document.form[0].ftp has no properties
If I tried alert message it is working.
javascript:RadioSelection(
But when I click nothing is working. I check the JavaScript console to find error and I got this error:
document.form[0].ftp has no properties
If I tried alert message it is working.
post your generated HTML here. the variable names that I used were the ones that I assumed you had. this might not be a true statement. Your radio button might have different name, also you might not be having a form for those radio buttons.. so that javascript needs a lot of work...
the function that I wrote was to give you an idea as how it can be written..
the function that I wrote was to give you an idea as how it can be written..
ASKER
<form method="POST" action="downloadnow.jsp" name="form">
<input type="radio" value="http" name="ip" >
<input type="radio" value="https" name="ip" >
<input type="radio" value="ftp" name="ip">
...
</form>
Also I tried removing name="ip" for all but in vain.
<input type="radio" value="http" name="ip" >
<input type="radio" value="https" name="ip" >
<input type="radio" value="ftp" name="ip">
...
</form>
Also I tried removing name="ip" for all but in vain.
all your radio buttons are named as "ip"... i.e.
if(document.form[0].ftp.checked) will return null!
it shd be
<form method="POST" action="downloadnow.jsp" name="form">
<input type="radio" value="http" name="http" >
<input type="radio" value="https" name="https" >
<input type="radio" value="ftp" name="ftp">
...
</form>
if(document.form[0].ftp.checked) will return null!
it shd be
<form method="POST" action="downloadnow.jsp" name="form">
<input type="radio" value="http" name="http" >
<input type="radio" value="https" name="https" >
<input type="radio" value="ftp" name="ftp">
...
</form>
ASKER
If I give different names ie http, https and ftp. Raido Button will allow user to select all 3 at a time.
But anywaz I tried what u said but still the same error. document.form[0].http has no properties
function RadioSelection(url)
{
if(document.form[0].http.c hecked)
{
//http is selected
url="http://"+url;
window.open(url);
}
if(document.form[0].https. checked)
{
//https is selected
url="https://"+url;
window.open(url);
}
if(document.form[0].ftp.checked)
{
//ftp is selected
url="ftp://"+url;
window.open(url);
}
}
But anywaz I tried what u said but still the same error. document.form[0].http has no properties
function RadioSelection(url)
{
if(document.form[0].http.c
{
//http is selected
url="http://"+url;
window.open(url);
}
if(document.form[0].https.
{
//https is selected
url="https://"+url;
window.open(url);
}
if(document.form[0].ftp.checked)
{
//ftp is selected
url="ftp://"+url;
window.open(url);
}
}
can you put all your generated HTML here. that way I can look at it in one go to see what we are missing
ASKER
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function RadioSelection(url)
{
if(document.form[0].http.c hecked)
{
//http is selected
url="http://"+url;
window.open(url);
}
if(document.form[0].https. checked)
{
//https is selected
url="https://"+url;
window.open(url);
}
if(document.form[0].ftp.checked)
{
//ftp is selected
url="ftp://"+url;
window.open(url);
}
}
</SCRIPT>
<body>
<form method="POST" action="downloadnow.jsp" name="form">
<table border="0" width="450" bgcolor="#EDECE9" style="border-collapse: collapse" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="30">HTTP<input type="radio" value="http" name="http"></td>
</tr>
<tr>
<td valign="top" width="30">HTTPS<input type="radio" checked value="https" name="https" ></td>
</tr>
<tr>
<td valign="top" width="30">FTP<input type="radio" value="ftp" name="ftp"></td>
</tr>
<tr>
<td class="tdnormal" colspan="2" align="center" bgcolor="#C0C0C0" class="WhiteHeader"> </td>
</tr>
</table>
<! -- JSP Code -->
out.print("<td><a href=\"javascript:RadioSel ection('"+ s+"');\">< image></a> </td></tr> ");
<! --Jsp code -->
</table>
</form>
</body>
</html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function RadioSelection(url)
{
if(document.form[0].http.c
{
//http is selected
url="http://"+url;
window.open(url);
}
if(document.form[0].https.
{
//https is selected
url="https://"+url;
window.open(url);
}
if(document.form[0].ftp.checked)
{
//ftp is selected
url="ftp://"+url;
window.open(url);
}
}
</SCRIPT>
<body>
<form method="POST" action="downloadnow.jsp" name="form">
<table border="0" width="450" bgcolor="#EDECE9" style="border-collapse: collapse" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="30">HTTP<input type="radio" value="http" name="http"></td>
</tr>
<tr>
<td valign="top" width="30">HTTPS<input type="radio" checked value="https" name="https" ></td>
</tr>
<tr>
<td valign="top" width="30">FTP<input type="radio" value="ftp" name="ftp"></td>
</tr>
<tr>
<td class="tdnormal" colspan="2" align="center" bgcolor="#C0C0C0" class="WhiteHeader">
</tr>
</table>
<! -- JSP Code -->
out.print("<td><a href=\"javascript:RadioSel
<! --Jsp code -->
</table>
</form>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
document.forms[0].ip has no properties
I really dont understand what is that showing up. I check line by line to see if I did any typo or missed something but seems like everything is the way you wanted it.
I really dont understand what is that showing up. I check line by line to see if I did any typo or missed something but seems like everything is the way you wanted it.
oops.. I am sorry in above code.. my cut & paste skilled went for a toss...:-)
function RadioSelection(url)
{
for(i=0;i<document.forms[0 ].ip.lengt h;i++;)//a tleast I should have closed the bracket!!!
{
if(document.forms[0].ip[i] .checked)
{
window.open(document.forms [0].ip[i]. value+s);
break;
}
}
}
now this function is correct..
function RadioSelection(url)
{
for(i=0;i<document.forms[0
{
if(document.forms[0].ip[i]
{
window.open(document.forms
break;
}
}
}
now this function is correct..
ASKER
well Kuldeep I noticed that missing ) and added but still it was not working. Also I guess your 'value+s' shoud be 'value+url'
I modified a little and now it is working let me know is this correct. Thought it is working but wanna make sure the logic is going correct or approach.
function RadioSelection(url)
{
for(i=0; i<3; i++)
{
if(document.form1.ip[i].ch ecked)
{
window.open(document.form1 .ip[i].che cked+url);
break;
}
}
}
I modified a little and now it is working let me know is this correct. Thought it is working but wanna make sure the logic is going correct or approach.
function RadioSelection(url)
{
for(i=0; i<3; i++)
{
if(document.form1.ip[i].ch
{
window.open(document.form1
break;
}
}
}
ASKER
something wrong in my code; Even if I select 'ftp' the window.open is opening 'https' the default selected one. hmmm....
you shd be changing this line
window.open(document.form1 .ip[i].che cked+url);
to
window.open(document.form1 .ip[i].val ue+url);
window.open(document.form1
to
window.open(document.form1
ASKER
Okay something is working. guess need minor change.
Let say URL page I'm operating be: http://myapplication/download.jsp
Let say 'url' value be 'serverapplication/downloa d/install. exe'
So what is happening rite now is if I select ftp:
I get NEW windows opened and URL on it is: http://myapplication/ftp://serverapplication/download/install.exe
I was guess I'll get the New windows with URL as 'ftp://serverapplication/download/install.exe'
Let say URL page I'm operating be: http://myapplication/download.jsp
Let say 'url' value be 'serverapplication/downloa
So what is happening rite now is if I select ftp:
I get NEW windows opened and URL on it is: http://myapplication/ftp://serverapplication/download/install.exe
I was guess I'll get the New windows with URL as 'ftp://serverapplication/download/install.exe'
I was guess I'll get the New windows with URL as 'ftp://serverapplication/download/install.exe'
that wd have been my guess as well..!!
function RadioSelection(url)
{
var newurl;
alert( 'I have recieved url as'+url);
for(i=0; i<3; i++)
{
if(document.form1.ip[i].ch ecked)
{
newurl=document.form1.ip[i ].checked+ url;
alert('window trying to open is'+newurl);
window.open(newurl);
break;
}
}
}
see what alerts your are getting
that wd have been my guess as well..!!
function RadioSelection(url)
{
var newurl;
alert( 'I have recieved url as'+url);
for(i=0; i<3; i++)
{
if(document.form1.ip[i].ch
{
newurl=document.form1.ip[i
alert('window trying to open is'+newurl);
window.open(newurl);
break;
}
}
}
see what alerts your are getting
ASKER
Ok seems like I resolved the problem with your help. Final Q, when I click on javascript I get NEW windows opened and it is 'doc' or 'pdf' it open in new browser but when it is 'exe' or so it ask for save or open. after I save. I have that new blank window opened. Can we close this window.
I think you shd be able to do that with java script "window.close();" problem is where to put that code.. because we are opening it straight from a url....
ASKER
Any Idea ??? How ????
ASKER
Can you have a look please