View Full Version : passing value to another page
bluez
09-13-2002, 06:16 AM
i want to pass jsp value to another jsp page.. does anyone know how can i do it??
sample code:
here is my button:
<input type="button" value="Save" name="save" onClick="savebtn('<%=year%>','<%=entity%>','<%=costpool%>','<%=strOption%>','<%=strValue%>')">
here is javascript:
function savebtn(yr,ety,cp,opt,val)
{
String year;
String entity;
String costpool;
String strOption;
String strValue;
year="yr";
entity="ety";
costpool="cp";
strOption="opt";
strValue="val";
win = window.open('another.jsp?year=year,entity=entity,costpool=costpool,ubr_choice=strOption,ubr_value=st rValue');
}
Can i know where went wrong??? it gave me errors
error: ; expected
x_goose_x
09-13-2002, 06:28 AM
Try:
function savebtn(yr,ety,cp,opt,val)
{
year=yr;
entity=ety;
costpool=cp;
strOption=opt;
strValue=val;
win = window.open('another.jsp?year='+year+',entity='+entity+',costpool='+costpool+',ubr_choice='+strOptio n+',ubr_value='+strValue+'');
}
bluez
09-13-2002, 06:36 AM
hi x_goose_x,
i have try your codes. but now it prompt me error : Object expected. what should i do??
bluez
09-13-2002, 06:40 AM
is the problem related with my another.jsp which is the another page??
code where i receive the value:
String year = request.getParameter("year");
String entity = request.getParameter("entity");
String costpool = request.getParameter("costpool");
String strOption = request.getParameter("ubr_choice");
String strValue = request.getParameter("ubr_value");
the above code is coded within jsp tag..
bluez
09-13-2002, 09:48 AM
thanks x_goose_x.. i try the code again. it works... but now got 1 problem... hope everyone can help mi..
when i use this code:
win = window.open('another.jsp? year='+year+',entity='+entity+',costpool='+costpoo
l+',ubr_choice='+strOption+',ubr_value='+strValue+
'');
all the values is pass into next page...
when i used the request.getParameter method.. it get the whole value as a string..
result : year=2000,entity=abc,costpool=123,ubr_choice=1,ubr_value=10
but what if i just want to have the values without the variables.. eg. i just want to have 2000,abc,123,1,10
Is there any other method that i can pass the values???
glenngv
09-13-2002, 10:12 AM
try:
win = window.open('another.jsp?year='+year+'&entity='+entity+'&costpool='+costpool+'&ubr_choice='+strOption+'&ubr_value='+strValue);
you can retrieve each parameter using request.getParameter method
bluez
09-13-2002, 11:03 AM
Glen.. thanks alot~~ :thumbsup: u r great! keke...
by the way, does anyone know how to make a window become invisibe. eg. when i click on the button, although it lead the user to a new window but i do not want the user to view it...
any methods that i can do it??
bluez
09-14-2002, 07:29 PM
anyone knows?
mordred
09-16-2002, 12:25 AM
Originally posted by bluez
by the way, does anyone know how to make a window become invisibe. eg. when i click on the button, although it lead the user to a new window but i do not want the user to view it...
I have troubles understanding what you actually want to achieve. If you mean browser windows with "window", comes the window.blur() method close to what you meant with "invisible"?
bluez
09-17-2002, 02:21 AM
mordred... thanks... i had try your win.blur() method. it is looking fine at first.. but after a while the window appears again...
my problem is now i have a button in one jsp page name jsp1... when user click on it... it links to another jsp page name jsp2 where it will allow the user to save that particular data in the jsp2.. but when it load the jsp2, a window pop out.. but i do not wish to let the user to see that window.. how to make it disappear??? i just want the jsp2 to run without letting the user to view that window..
y i need to open a window when i do not wan the user to view?? its because if i do not open a new window.. when the jsp2(which has no interface) is excuted i cannot click any links in the jsp1 anymore.. cause it will lost contact with jsp1...
anyone can give me a solution???
glenngv
09-17-2002, 02:31 AM
position the window outside of the screen.
window.open("URLhere","","left=8000,top=6000");
but it only works with IE.
bluez
09-17-2002, 02:38 AM
thanks glenngv.. although the window doesnt appear.. but at the tool bar below... it still shows that it had open a new window... how??
bluez
09-17-2002, 03:04 AM
is there any method when the downloading is finish, i can close the window??
glenngv
09-17-2002, 03:16 AM
Originally posted by bluez
thanks glenngv.. although the window doesnt appear.. but at the tool bar below... it still shows that it had open a new window... how??
well, then use a hidden frame instead.
bluez
09-17-2002, 06:18 AM
thanks... you are :thumbsup:
;)
bluez
09-18-2002, 02:37 AM
sorri i got 1 problem... if my jsp2 had finish saving the data, how do i let the jsp1 know it??? anyone can give me suggestions??
glenngv
09-18-2002, 02:54 AM
are you using hidden frame or new window?
bluez
09-18-2002, 03:41 AM
i am using the new window. currently i put the setTimeout to let it close automatically.. but i think it is not so good. i wan to pass something from jsp2 to let jsp1 knows that it had finishes the downloading.. what should i do??Sorry to trouble you again..
glenngv
09-18-2002, 04:58 AM
i think it is better just to close the pop up automatically.
why do you want the parent window to know when the popup window finishes execution? what shall the parent window then? is there something the parent window will do after the execution in the popup?
bluez
09-18-2002, 05:04 AM
the parent is not having any execution after the saving.. but it is hard to managed.. because i dunno the downloading time. if i set too less, maybe it will close before having any execute the jsp2. if i set too much, it will be a waste of time... everytime the execution of the jsp2 finishes is different.. so i think it will be better if the jsp2 finishes and alert the jsp1 to close the window. Can give me some ideas on how to do it??
glenngv
09-18-2002, 05:43 AM
does the parent control when to close the popup?
it's better to put the automatic close script in the popup itself like this:
<body onload="setTimeout('window.close()',3000)">
this way, the parent need not know when the execution in the popup will finish
bluez
09-18-2002, 06:10 AM
ok... thanks alot. by the way, if my website consists two frames. i put the button in frame1, is it possible to know which page is loaded in frame2 when user click on the button???
glenngv
09-18-2002, 06:20 AM
this post has come a long way with different topics :)
anyway, here's the solution:
<input type="button" value="Page" onclick="alert('The URL in frame2 is:\n'+top.frames['NameOfFrame2Here'].location.href);">
bluez
09-18-2002, 06:26 AM
thanks..:o
bluez
09-18-2002, 08:12 AM
sorry guys i have one more question that i had some doubt.. can i call to a javascript function from another page?? that means when i am in page1 can i call to the javascript in page2??
glenngv
09-18-2002, 08:26 AM
as long as the two windows or frames are open, you can call functions from one to the other and vice versa.
if from page1 (parent) you open page2 (child) in a new window.
you can call function in parent from child like this:
window.opener.yourFunctionInParentHere()
if you want the other way around:
var winHandle = window.open("URLhere");
then you can call the function later:
winHandle.yourFunctionInChildHere()
bluez
09-18-2002, 08:35 AM
sorry, i am not calling the javascript function from a new window.. eg i have two frames, page1 in frame1 is calling the function from page2 in frame2.. izit possible?? but i do not want to open a new window... can i do that??
bluez
09-18-2002, 08:42 AM
Originally posted by bluez
sorry, i am not calling the javascript function from a new window.. eg i have two frames, page1 in frame1 is calling the function from page2 in frame2.. izit possible?? but i do not want to open a new window... can i do that??
eg. in frame1... i have this image
<img src="save.gif" width="85" height="18" alt="Save" onClick="savebtn()">-----it is calling a function in another page.
in frame2... it is a jsp page.
inside the jsp page i have this function
function savebtn(yr,opt,val)
{
year=yr;
option=opt;
val=val;
win = window.open('another.jsp?year='+year+'&choice='+option+'&value='+val+'','done','left=8000,top=6000');
}----this function will call to another jsp page with the parameters.
will this work out??
glenngv
09-18-2002, 08:43 AM
top.frames["frameNameHere"].functionNameHere()
bluez
09-18-2002, 08:50 AM
sorry is it this way?? <img..... onClick="top.frames["main"].savebtn()">
the frame name is the frame that i am reference to, right?? what about the top.frames?? Sorry to trouble you. :confused:
bluez
09-18-2002, 08:56 AM
by they way, can i capture the variable in the other page as well?? :(
glenngv
09-18-2002, 09:01 AM
that is correct
onClick="top.frames["main"].savebtn()">
did you try it? it seems you are afraid to try it first.
to access a variable (which must be global):
top.frames["main"].variableNameHere
bluez
09-18-2002, 09:11 AM
yes. i have try it... but the button doesnt seems working... it cant link to that page. it prompt me page couldnt be found.
bluez
09-18-2002, 09:33 AM
mm..glenngv thanks alot for your help. i think it is hard to implement this way. maybe i shall think of another solution... anyway, you are great. :thumbsup: heehee :D
mordred
09-18-2002, 02:26 PM
The onclick event handler contained invalid syntax, you need to enclose the frame name in single quotes (just like in Java, JSP...):
onClick="top.frames['main'].savebtn()"
glenngv
09-19-2002, 02:03 AM
Originally posted by mordred
The onclick event handler contained invalid syntax, you need to enclose the frame name in single quotes (just like in Java, JSP...):
onClick="top.frames['main'].savebtn()"
not really:
onClick="top.frames['main'].savebtn()"
has the same effect as:
onClick='top.frames["main"].savebtn()'
i just didnt notice that bluez' post is:
onClick="top.frames["main"].savebtn()"
which i said was correct (at least for the logic not the syntax :))
bluez
09-19-2002, 02:11 AM
thanks alot.. i had changed that.. it works. thanks to both of you.
but is the capturing of variable correct?? can i put the value that i pass from other page in a variable??
like : String var = "top.frames['main'].values";
glenngv
09-19-2002, 02:37 AM
Originally posted by bluez
thanks alot.. i had changed that.. it works. thanks to both of you.
but is the capturing of variable correct?? can i put the value that i pass from other page in a variable??
like : String var = "top.frames['main'].values";
are you talking of captuaring a javascript variable into a JSP variable? I noticed you use String var. this is not possible.
but if you mean javascript variable
var myVar = top.frames['main'].value;
with no quotes and not .values
bluez
09-19-2002, 02:38 AM
Originally posted by bluez
thanks alot.. i had changed that.. it works. thanks to both of you.
but is the capturing of variable correct?? can i put the value that i pass from other page in a variable??
like : String var = "top.frames['main'].values";
for the onclick="top.frames['main'].functionName()";
can i put it into a function?? actually my idea is when user click on the button, it will go to a function. In that function, i will capture the values in the another frame which is also another page. then after capturing the values, i will call the function in the other frame as well. can i do that??
glenngv
09-19-2002, 03:01 AM
yes
bluez
09-19-2002, 03:27 AM
thanks ;)
bluez
09-19-2002, 03:44 AM
eh...sorry i have one more question again. when i click on the save button in the frame1 it will call the function in the frame2, jsp page1. the function will call to a jsp page2 but at the same time the frame2 interface will show page not found.
my jsp2 is a jsp page without interface. how can i make the jsp page1 to remain in frame2 when i click on the save button and at the same time user will be able to click on the hyperlinks in the jsp page1???
last time i use a window.open to make the jsp page1 still available while executing another page. but this time round the window.open method cant help.. is there any other way??
sorry to trouble u all again.. :o
bluez
09-19-2002, 03:55 AM
hehe... i have the problem solved.. sorry to trouble you guys.. thanks alot for your help... thanks.. :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.