Link to home
Start Free TrialLog in
Avatar of princehyderabad
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.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 !!
ASKER CERTIFIED SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of princehyderabad
princehyderabad

ASKER

I guess that was answer to my Q1. But still my Q2 unresolved ?
Can you have a look please
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....
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>
------------------------------------------
                           
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>);
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
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 ........
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</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>");
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 ??
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..
Yes I tried using alert msg. Its not working.

My JSP code:

out.print("<td><a href='javascript:RadioSelection("+s+")'><image></a></td></tr>");
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

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>");
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')'>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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..
<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.
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 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);
            }

}
can you put all your generated HTML here. that way I can look at it in one go to see what we are missing
<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>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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..
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;
        }
    }

}

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].checked+url);
to
window.open(document.form1.ip[i].value+url);
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'
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
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....
Any Idea ??? How ????