Re: Pass html form data in bi-directional ways (undefined data)
From: Viatcheslav V. Vassiliev (msnewsgroup_at_www-sharp.com)
Date: 03/07/04
- Next message: Troels Jakobsen: "Re: undefined data in javascript"
- Previous message: Matt: "undefined data in javascript"
- In reply to: Matt: "Re: Pass html form data in bi-directional ways (undefined data)"
- Next in thread: Matt: "Re: Pass html form data using JavaScript object in bi-directional ways"
- Reply: Matt: "Re: Pass html form data using JavaScript object in bi-directional ways"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 7 Mar 2004 12:26:07 +0300
<body onload="window_onload()">
Function defined here runs when page is completely loaded, your
document.write(id) runs when page is loading and window_onload was not
called yet. Because dialogArguments is available when page2 is loading you
may assign id in script's global part (and comment or remove in
window_onload()):
var opener = window.dialogArguments;
var id = opener.all.id.value;
//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
"Matt" <mattloude@hotmail.com> сообщил/сообщила в новостях следующее:
news:uV5QQKBBEHA.712@tk2msftngp13.phx.gbl...
> Viatcheslav:
>
> Now I modified page1.html and page2.html, I add one more text field called
> id, however, in page2.html, field id is read only, I get undefined data
for
> id variable in page2.html. Here's the code: Please see the arrow below.
> Please advise. Thanks!!!
>
> //page1.html
> <html>
> <head>
> <script type="text/javascript">
> function openwindow()
> {
> window.showModalDialog("page2.html", document, "menubar=no,
titlebar=no,
> toolbar=no, location=no, directories=no, status=no,
> menubar=no,scrollbars=yes, resizable=no, copyhistory=yes, width=400,
> height=500");
> }
> </script>
> </head>
> <body">
> <H2>Page 1</H2>
> <P>name: <input type="text" name="fname">
> <P>id: <input type="text" name="id">
> <P><input type="button" value="validate" onclick="openwindow()">
> </body>
> </html>
>
> ------------------------------------------------------------------
> //page2.html
> <html>
> <head>
> <script type="text/javascript">
> var opener = window.dialogArguments;
> var id;
> function window_onload()
> {
> fname.value = opener.all.fname.value;
> id = opener.all.id.value;
> alert("ID = " + id); //<==== able to get the data
> }
> function OK()
> {
> opener.all.fname.value = fname.value;
> window.close();
> }
> </script>
> </head>
> <H2>Page 2</H2>
> <body onload="window_onload()">
> <P>name: <input type="text" name="fname">
> <P>id = <script type="text/javascript">document.write(id);</script>
> //<============== undefined data
> <P><input type="button" value="validate" onClick="OK()">
> </body>
> </html>
>
>
>
> "Matt" <mattloude@hotmail.com> wrote in message
> news:eTYqti$AEHA.2628@TK2MSFTNGP11.phx.gbl...
> > Thanks Viatcheslav,
> >
> > this is exactly what I want. If I need to create page3.html, and pass
> object
> > between page1.html, page2.html, and page3.html, then the code of
> page3.html
> > will be the same as page2.html, and add the following in page2.html's
OK()
> > function.
> >
> > window.showModalDialog("page3.html", document, ...);
> >
> > I wonder if page3.html can pass that object directly to page1.html,
> without
> > going through page2.html??
> >
> > Please advise. Thanks!
> >
> >
> > "Viatcheslav V. Vassiliev" <msnewsgroup@www-sharp.com> wrote in message
> > news:#KRJV62AEHA.3400@tk2msftngp13.phx.gbl...
> > > You may pass any object in window.showModalDialog, for example, page1
> > > document
> > >
> > > var myObject = document;
> > > window.showModalDialog("page2.html", myObject, ...);
> > >
> > > and manipulate this document in script in page2:
> > >
> > > //page1.html
> > > <html>
> > > <head>
> > > <script>
> > > function openwindow()
> > > {
> > > window.showModalDialog("page2.html", document,
> > > "menubar=no, titlebar=no, toolbar=no, location=no, directories=no,
> > > status=no, menubar=no,scrollbars=yes, resizable=no, copyhistory=yes,
> > > width=400, height=500");
> > > }
> > > </script>
> > > </head>
> > > <body">
> > > <H2>Page 1</H2>
> > > <P>name: <input type="text" name="fname">
> > > <P><input type="button" value="validate" onclick="openwindow()">
> > > </body>
> > > </html>
> > >
> > > //page2.html
> > > <html>
> > > <head>
> > > <script>
> > > var opener = window.dialogArguments;
> > >
> > > function window_onload()
> > > {
> > > fname.value = opener.all.fname.value;
> > > }
> > > function OK()
> > > {
> > > opener.all.fname.value = fname.value;
> > > window.close();
> > > }
> > > </script>
> > > </head>
> > > <H2>Page 2</H2>
> > > <body onload="window_onload()">
> > > <P>name: <input type="text" name="fname">
> > > <P><input type="button" value="validate" onclick="OK()">
> > > </body>
> > > </html>
> > >
> > > //------------------------------------
> > > Regards,
> > > Vassiliev V. V.
> > > http://www-sharp.com -
> > > Scripting/HTA/.Net Framework IDE
> > >
> > >
> > >
> > > "Matt" <mattloude@hotmail.com> сообщил/сообщила в новостях следующее:
> > > news:eLCxV$0AEHA.3436@tk2msftngp13.phx.gbl...
> > > > I have 2 html pages, both have a text box and a button. In
page1.html,
> > > when
> > > > the user enter a text in text box, and click button, it will pass
the
> > form
> > > > data to page2.html, and it will open page2.html in a smaller window
> and
> > > that
> > > > data will show in text box in page2.html. In page2.html, if the user
> > > changes
> > > > the text box data and click the button, it will update the data in
> > > existing
> > > > window for page1.html. In other words, data can transfer back and
> forth
> > in
> > > > page1.html and page2.html.
> > > >
> > > > I already wrote the html pages as shown below. However, after
clicking
> > the
> > > > button in page1.html, the data can be shown in text box in
page2.html,
> > > > But when user changes the text box data in page2.html, it will open
> > > another
> > > > window for page1.html, not change the data in existing window for
> > > > page1.html, and data cannot shown in new window for page1.html also.
> > > > I am just using regular button, and i am not using submit button.
> > > >
> > > > any ideas? Please advise. Thanks!
> > > >
> > > > -------------- page1.html ----------------------------
> > > > <html>
> > > > <head>
> > > > <script>
> > > > function openwindow()
> > > > { var myObject = new Object();
> > > > myObject.firstName = fname.value;
> > > > alert(myObject.firstName);
> > > > var sReturn = window.showModalDialog("page2.html", myObject,
> > "menubar=no,
> > > > titlebar=no, toolbar=no, location=no, directories=no, status=no,
> > > menubar=no,
> > > > scrollbars=yes, resizable=no, copyhistory=yes, width=400,
> height=500");
> > > > }
> > > > function window_onload()
> > > > { alert("window onload...");
> > > > if (window.dialogArugments != null)
> > > > {
> > > > alert("window.dialogArguments != null");
> > > > var oMyObject = window.dialogArguments;
> > > > fname.value = oMyObject.firstName;
> > > > }
> > > > else
> > > > { alert("window.dialogArguments = null");
> > > > }
> > > > }
> > > > </script>
> > > > </head>
> > > > <body onload="window_onload()">
> > > > <H2>Page 1</H2>
> > > > <P>name: <input type="text" name="fname">
> > > > <P><input type="button" value="validate" onclick="openwindow()">
> > > > </body>
> > > > </html>
> > > >
> > > >
> > > > ------------------------ page2.html --------------------------
> > > > <html>
> > > > <head>
> > > > <script>
> > > > function openwindow()
> > > > { var myObject = new Object();
> > > > myObject.firstName = fname.value;
> > > > alert(myObject.firstName);
> > > > var sReturn = window.showModalDialog("page1.html", myObject,
> > "menubar=no,
> > > > titlebar=no, toolbar=no, location=no, directories=no, status=no,
> > > menubar=no,
> > > > scrollbars=yes, resizable=no, copyhistory=yes, width=400,
> height=500");
> > > > }
> > > > function window_onload()
> > > > { alert("window onload...");
> > > > // if (window.dialogArugments != null)
> > > > // {
> > > > // alert("window.dialogArguments != null");
> > > > var oMyObject = window.dialogArguments;
> > > > fname.value = oMyObject.firstName;
> > > > // }
> > > > // else
> > > > // { alert("window.dialogArguments = null");
> > > > // }
> > > > }
> > > > </script>
> > > > </head>
> > > > <H2>Page 2</H2>
> > > > <body onload="window_onload()">
> > > > <P>name: <input type="text" name="fname">
> > > > <P><input type="button" value="validate" onclick="openwindow()">
> > > > </body>
> > > > </html>
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Troels Jakobsen: "Re: undefined data in javascript"
- Previous message: Matt: "undefined data in javascript"
- In reply to: Matt: "Re: Pass html form data in bi-directional ways (undefined data)"
- Next in thread: Matt: "Re: Pass html form data using JavaScript object in bi-directional ways"
- Reply: Matt: "Re: Pass html form data using JavaScript object in bi-directional ways"
- Messages sorted by: [ date ] [ thread ]