• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

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.getString(6)+"</td>");
                                out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td></tr>");
                                path.add(rs.getString(10)+rsgetString(6));
                                           if (rs.next()) {
                                               out.print("<tr><td valign='top' class='tdnormal'>"+rs.getString(6)+"</td>");                                          
                                               out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td></tr>");
                                               path.add(rs.getString(10)+rsgetString(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 !!
0
princehyderabad
Asked:
princehyderabad
  • 19
  • 15
3 Solutions
 
KuldeepchaturvediCommented:
well your table looks okay to me....
as for as what button got is concern, you will have to wirte javascript for that..

something like..

("<td><a href='javascript:RadioSelection("+s+")"><image></a></td>");                    


in the page your script will look like..
//assuming your radio buttons are called ftp,http,https
function RadioSelection(url)
{
if(document.form[0].ftp.checked)
{
//ftp is selected
url="ftp://"+url;
window.open(url);
}
if(document.form[0].http.checked)
{
//http is selected
url="http://"+url;
window.open(url);
}
if(document.form[0].https.checked)
{
//https is selected
url="https://"+url;
window.open(url);
}

}
0
 
princehyderabadAuthor Commented:
I guess that was answer to my Q1. But still my Q2 unresolved ?
Can you have a look please
0
 
KuldeepchaturvediCommented:
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.getString(6)+"</td>");
                                out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td></tr>");

which will put them in one table..
so you already have the code....
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
princehyderabadAuthor Commented:
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>
------------------------------------------
                           
0
 
princehyderabadAuthor Commented:
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>);
0
 
KuldeepchaturvediCommented:
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.getString(6)+"</td>");
                                out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td></tr>");
                                path.add(rs.getString(10)+rsgetString(6));
                                           if (rs.next()) {
                                               out.print("<tr><td valign='top' class='tdnormal'>"+rs.getString(6)+"</td>");                                          
                                               out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td></tr>");
                                               path.add(rs.getString(10)+rsgetString(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
0
 
princehyderabadAuthor Commented:
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 ........
0
 
princehyderabadAuthor Commented:
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.
0
 
KuldeepchaturvediCommented:
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</td><td>Path</td>");
ArrayList path = new ArrayList();
 while (rs.next()) {
out.print("<tr>");                                
out.print("<td valign='top' class='tdnormal'>"+rs.getString(6)+"</td>");
                                out.print("<td valign='top' class='tdnormal'>"+rs.getString(8)+"</td>");
                               out.print(<td valign='top' class='tdnormal' ><a href=javascript:RadioButton("+rs.getString(10)+rsgetString(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>");
0
 
princehyderabadAuthor Commented:
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/download.exe)
When I click nothting working ??
0
 
KuldeepchaturvediCommented:
we will need to put "" around it...
is should come as "javascript:RadioSelecttion(it/test/download.exe);"

also just to check put alerts in your javascript function to see if its getting invoked or not..
0
 
princehyderabadAuthor Commented:
Yes I tried using alert msg. Its not working.

My JSP code:

out.print("<td><a href='javascript:RadioSelection("+s+")'><image></a></td></tr>");
0
 
princehyderabadAuthor Commented:
on Status Bar I can see: javascript:RadioSelection(it/test/download.exe)

Error on Mozilla Browser:  Missing ( arugment list
Error on IE: "it" is undefined

0
 
KuldeepchaturvediCommented:
yup we need to put quotes around it it should be

javascript:RadioSelection('it/test/download.exe')

in your jsp change the line

out.print("<td><a href='javascript:RadioSelection("+s+")'><image></a></td></tr>");
to have quotes in it
out.print("<td><a href='javascript:RadioSelection('"+s+"')'><image></a></td></tr>");
0
 
princehyderabadAuthor Commented:
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:RadioSelection('it/test/download.exe')'>
0
 
KuldeepchaturvediCommented:
oh yes that will happen...

see your source is saying
<a href='javascript:RadioSelection('it/test/download.exe')'>

i.e. first quote and second quote only have 'javascript:RadioSelection(' between them..

<a href="javascript:RadioSelection('it/test/download.exe');">
this is how your generated source shd look like for your javascript to invoke..
0
 
princehyderabadAuthor Commented:
Okay now I made it look the way U wanted on status bar I can see this:
javascript:RadioSelection('it/test/download.exe');

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.
0
 
KuldeepchaturvediCommented:
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..
0
 
princehyderabadAuthor Commented:
<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.
0
 
KuldeepchaturvediCommented:
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>

0
 
princehyderabadAuthor Commented:
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.checked)
                {
                //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);
            }

}
0
 
KuldeepchaturvediCommented:
can you put all your generated HTML here. that way I can look at it in one go to see what we are missing
0
 
princehyderabadAuthor Commented:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function RadioSelection(url)
{
           if(document.form[0].http.checked)
                {
                //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">&nbsp;</td>
                                  </tr>
                                   </table>
<! -- JSP Code -->
out.print("<td><a href=\"javascript:RadioSelection('"+s+"');\"><image></a></td></tr>");
<! --Jsp code -->
</table>
</form>
</body>
</html>
0
 
KuldeepchaturvediCommented:
my fault, I shd have been using forms[0] instead of form[0]
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function RadioSelection(url)
{
for(i=0;i<document.forms[0].ip.length;i++
{
if(document.forms[0].ip[i].checked)
{
window.open(document.forms[0].ip[i].checked+s);
break;
}
}
}
</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="ip"></td>                                          
                                      </tr>
                                      <tr>
                                           <td valign="top" width="30">HTTPS<input type="radio" checked  

value="https"  name="ip" ></td>                                      
                                      </tr>
                                      <tr>
                                           <td valign="top" width="30">FTP<input type="radio"

value="ftp"  name="ip"></td>
                                      </tr>

                                    <tr>

                                         <td class="tdnormal" colspan="2" align="center"

bgcolor="#C0C0C0" class="WhiteHeader">&nbsp;</td>
                                 </tr>
                                  </table>
0
 
princehyderabadAuthor Commented:
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.
0
 
KuldeepchaturvediCommented:
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.length;i++;)//atleast 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..
0
 
princehyderabadAuthor Commented:
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].checked)
        {
        window.open(document.form1.ip[i].checked+url);
        break;
        }
    }

}

0
 
princehyderabadAuthor Commented:
something wrong in my code; Even if I select 'ftp' the window.open is opening 'https' the default selected one. hmmm....
0
 
KuldeepchaturvediCommented:
you shd be changing this line
window.open(document.form1.ip[i].checked+url);
to
window.open(document.form1.ip[i].value+url);
0
 
princehyderabadAuthor Commented:
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/download/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'
0
 
KuldeepchaturvediCommented:
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].checked)
        {
newurl=document.form1.ip[i].checked+url;        
alert('window trying to open is'+newurl);
window.open(newurl);
        break;
        }
    }

}
see what alerts your are getting
0
 
princehyderabadAuthor Commented:
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.
0
 
KuldeepchaturvediCommented:
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....
0
 
princehyderabadAuthor Commented:
Any Idea ??? How ????
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 19
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now