Forum Moderators: open

Message Too Old, No Replies

passing variables between pages

help with technique

         

cudaboy_71

6:57 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



i'm a novice javascripter. and, i need some guidance on how to handle a problem.

i am working on a popup script that processes some text entry to write back to a DB file. the particular field that gets updated is dependent upon the particular form submitted by the popup's window.opener.

there are 12 unique forms (correlating with the 12 fields in the DB) on the window.opener. but, they may all be modified by the same popup.

however, i'm having difficulty figuring out how to tell the popup which form was submitted.

at the beginning of the popup i define some variables like:


var BR4 = window.opener.formname.BR3.value;

but 'formname' needs to be the actual name of the form in the window.opener. i'm having trouble A) figuring out how to get the window.opener to pass that information. and B) getting my var BR (for example) to accept the variable in that declaration.


var BR4 = window.opener."+formname+".BR3.value;

for example, does not work.

is there a basic technique here for doing this? thanks.

orion_rus

9:52 am on Mar 18, 2005 (gmt 0)

10+ Year Member



I don't understand you clearly. But i think so.
Your submit buttons have different names and in a server side you make choose by this names. In a server side you should place to a $_SESSION variable a value equal to a submited submit button name. And in the client side just search this $_SESSION for name and make equal output...
I hope i was clear
Good luck to you

Bernard Marx

11:39 am on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var BR4 = window.opener."+formname+".BR3.value; // XXX

var BR4 = window.opener.document.forms[strFormName].BR3.value;

cudaboy_71

7:58 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



thank you both so much. that's exactly what i needed. i'm glad you were able to decipher what i was trying to do enough to get those suggestions out.

FYI, i dont think i have the tools (or knowledge) to do serverside JavaScripting. so, i just declare an ASP session variable inside each form i'm submitting like:


<input type="hidden" name ="whatever" value="<%Session("FORMNAME")="the_name_of_this_particular_form"%>

then, in the popup i can query it with:


var BR4=window.opener.<%=Session("FORMNAME")%>.BR3.value;

works like a champ!

cudaboy_71

10:26 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



well. i thought i was out of the woods. but, not so fast.

my brilliant idea had a fatal flaw: the ASP i wrote ignored the HTML it was embedded in. (seemed like a good idea at the time--i'll call it caffeine deprivation)

well, here is some code to illustrate exactly where i'm having trouble. if anyone can help again, i'd appreciate it.

initially i present a page of form elements via ASP that display as buttons. there are 12 different forms similar to below, with the exception that they all have different form names to modify different fields of the DB--the field 'Photo' in the case below.


<form name="photoform" method="post" action="popup.asp" onsubmit="showpopup(); return false">
<INPUT Type="hidden" Name="BR3" Value="<%=(maintbr2)%>">
<INPUT Type="hidden" Name="SC2" Value="<%=(maintsc)%>">
<INPUT Type="hidden" Name="FM" Value="<%=mySQL("family")%>">
<INPUT Type="hidden" Name="field" Value=Photo>
<INPUT Type="submit" onClick="showPopup()" value="Edit photo for <%=mySQL("family")%>">
</FORM>

as you can see from above, clicking on a button opens a popup. the popup has a text field that will write its contents back to the DB.

my problem is that i need to pass the name of the form clicked in the code above to the popup so that i can create a variable in the popup to query the proper form's hidden data:


var BR4 = window.opener.VARIABLE.BR3.value;
var SC3 = window.opener.VARIABLE.SC2.value;

where VARIABLE is the name of the form submitted in the window.opener

this is where my limited experience comes in. i really have no idea of how to accomplish this.

i've pondered on this a while and come up with a couple of unworking ideas. for example, one thought was to add a session variable to the ASP and assign it in the form that gets submitted.


<INPUT Type="hidden" value="<%Session("FORMNAME")="photoform"%>">

but, that doesnt work. the ASP parser ignores this html version of a CASE variable and assigns the variable every time it sees it. so, the last assignment on the page is the value (the name of the 12th form).