Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

losing form elements and referer when opening in a javascript window

Guest
Jan 21, 2010 Jan 21, 2010

I am submitting from a.cfm to b.cfm. b.cfm opens in a Javascript window. In b.cfm, the form elements from a.cfm are lost and cgi.referer returns nothing.

When I don't open b.cfm in a Javascript window, everything is ok.

What is this happening?

TOPICS
Getting started
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 04, 2010 Feb 04, 2010

Perhaps, even neater:

function f(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;
            document.forms[0].target=nextwin_;

etc., etc

}

Translate
Advocate ,
Jan 21, 2010 Jan 21, 2010

Hi,

Can you please post your complete code here?.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2010 Jan 21, 2010

NOw it is aa.cfm and bb.cfm. aa.cfm is the first one, bb.cfm the second one.

<html>
   <head>
      <script language="javascript">
         function fie_(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            if (_br=='Microsoft Internet Explorer')
            {
                _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                _attrs=_attrs+'top=0,left=0';
                window.opener=null;
                window.close();
                window.open(nextpg_,nextwin_,_attrs)
            }
            else
               {
                  alert('Internet Explorer Please.')
               }
         }
      </script>
   </head>
   <body>
      <form>
         <input name="aabb" type="text" value="0">
         <input type="submit" value="*" onClick="fie_('bb.cfm','x')">  <!---  onClick="fie_('bb.cfm','x')" --->
      </form>
   </body>
</html>

<html>
   <head>
      <title>
      </title>
<!---      <meta http-equiv="refresh" content="5"> --->
   </head>
   <body>
      <cfoutput>
         ___*#aabb#*___*#cgi.referer#*___*#cgi.script_name#*___*#now()#*
      </cfoutput>
      <form>
         <input type="submit" value="**">
      </form>
   </body>
</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2010 Jan 21, 2010

It's because you are using javascript.  If you really need a new window, target = "blank" is a lot simpler.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

I am submitting from a.cfm to b.cfm. b.cfm opens in a Javascript window. In b.cfm, the form elements from a.cfm are lost and cgi.referer returns nothing. When I don't open b.cfm in a Javascript window, everything is ok.

What is this happening?

The reason is simple really. Your code does not submit the form! Replace your Javascript with the following, and you will see it for yourself

<script language="javascript">
     function fie_(nextpg_,nextwin_)
     {
        var _attrs='';
        var _br=navigator.appName;
        if (_br=='Microsoft Internet Explorer')
        {
            _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
            _attrs=_attrs+'top=0,left=0';
            window.opener=null;
            // window.close();
             // window.open(nextpg_,nextwin_,_attrs)

        }
        else
           {
              alert('Internet Explorer Please.')
           }
         // submit form to the page nextpg_
          document.forms[0].action=nextpg_;

     }
</script>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 28, 2010 Jan 28, 2010

Should have seen that. Tried putting action in but no luck.Also tried putting in method="post" in form tag. Still cannot get value to next page. Any suggestions would be appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2010 Jan 28, 2010

When I use your code, plus the modified script I showed in my last post, the values appear on the action page. Start from there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 01, 2010 Feb 01, 2010

The problem is when the line that says     window.open(nextpg_,nextwin_,_attrs)     is uncommented.

It works when bbb.cfm opens in a regular browser window but  "variable aabb not defined" when try to open in window.

I hope to find out what I'm doing wrong and also try sending aabb with method get.

Edit--Got it to work with method get. Still want to send over form element without passing as params.

Message was edited by: lwfg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2010 Feb 01, 2010

You should set up the form attributes before the window opens. Like this, for example

<script language="javascript">
         function fie_(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;

            if (_br=='Microsoft Internet Explorer')
            {
                _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                _attrs=_attrs+'top=0,left=0';
                window.opener=null;
                // window.close();
                window.open(nextpg_,nextwin_,_attrs)
            }
            else
               {
                  alert('Internet Explorer Please.')
               }
               
         }
      </script>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 02, 2010 Feb 02, 2010

Thanks, that makes sense. I'm surprised the same thing's happenning though.

-- If aaaa.cfm submits to bbbb.cfm without openning a Javascript window, the value of a passes along fine.

-- Passing a as a parameter in the url works too.

-- It's when I try to open bbbb.cfm in a Javascript window that I get the error "variable a undefined".

-- Someone had a similar problem, http://www.tek-tips.com/viewthread.cfm?qid=1441288&page=19 .Adapted it but had to pass parameter in url.

What can I do to make his work with a submit or button type?

This is aaaa.cfm

<html>
   <head>
      <script language="javascript">
         function fie_(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;
            if (_br=='Microsoft Internet Explorer')
            {
                _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                _attrs=_attrs+'top=0,left=0';
                window.opener=null;
                //window.close();
                window.open(nextpg_,nextwin_,_attrs)
            }
            else
            {
              alert('Internet Explorer Please.')
            }
         }
      </script>

      <title>
      </title>

   </head>
   <body>
      <form name="f">

         <cfset a=0>
         <cfoutput>
            <input name="a" type="text" value="#a#">
         </cfoutput>

         <input name="sf" type="submit" value="*" onClick="fie_('bbbb.cfm,''x')">

      </form>
   </body>
</html>

This is bbbb.cfm

<html>
   <head>
      <title>
      </title>
   </head>
   <body>

      <cfoutput>
         *#a#*#now()#*
      </cfoutput>

   </body>
</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2010 Feb 02, 2010

There's nothing the matter. You simply made a typing mistake.

fie_('bbbb.cfm,''x')

Should be: fie_('bbbb.cfm','x')

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2010 Feb 04, 2010

Still getting the same thing.

When sf is clicked in aaaa.cfm, bbbb.cfm does not see the variable named "a".

When the link with the * is clicked, bbbb.cfm sees "a".

What on earth am I doing wrong?

This is aaaa.cfm.

<html>
   <head>
      <script language="javascript">
         function f(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;
            if (_br=='Microsoft Internet Explorer')
            {
                _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                _attrs=_attrs+'top=0,left=0';
                window.opener=null;
                window.close();
                window.open(nextpg_,nextwin_,_attrs)
            }
            else
            {
              alert('Internet Explorer Please.')
            }
         }

         function g(nextpg_,nextwin_,val)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;
            if (_br=='Microsoft Internet Explorer')
            {
                _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                _attrs=_attrs+'top=0,left=0';
                window.opener=null;
                window.close();
                window.open(nextpg_+'?a='+val,nextwin_,_attrs)
            }
            else
            {
              alert('Internet Explorer Please.')
            }
         }

      </script>
      <title>
      </title>
   </head>
   <body>
      <form name="ff">
         <cfset a=0>
         <cfoutput>
            <input name="a" type="text" value="#a#">
         </cfoutput>

         <input name="sf" type="submit" value="*" onClick="f('bbbb.cfm','windowname')">
         <a href="javascript:g('bbbb.cfm','x','<cfoutput>#a#</cfoutput>')">
            *
         </a>
      </form>
   </body>
</html>

This is bbbb.cfm

<html>
   <head>
      <title>
      </title>
   </head>
   <body>
      <cfoutput>
         *#a#*#now()#*
      </cfoutput>
   </body>
</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2010 Feb 04, 2010

Could you please have the courtesy to acknowledge questions that have been answered, before proceeding to ask further questions? I have answered at least 2 questions. What you've simply been doing is add more script, yet saying you don't know what you are doing wrong!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2010 Feb 04, 2010
What on earth am I doing wrong?

This time?

<a href="javascript:g('bbbb.cfm','x','<cfoutput>#a#</cfoutput>')">
            *
         </a>

I would put the cfoutput tag outside, like this:

<cfoutput><a href="javascript:g('bbbb.cfm','x','#a#')">open page bbbb</a></cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2010 Feb 04, 2010

BKBK, Sorry that I seemed discourteous. I never meant to be.

The "more script" was just my latest tries.

g() works tags inside or out but thank you for the suggestion about putting the tags outside.

Still don't understand why f() won't work when opening a new window but does work when not opening a new window.

Again,I guess I should've acknowleged each of your replies as they came. I really do appreciate your time and effort.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2010 Feb 04, 2010
why f() won't work when opening a new window but does work when not opening a new window.

To correct that, specify the new window as target for the form.

<body>
      <form name="ff" target="windowname">
         <cfset a=0>
         <cfoutput>
            <input name="a" type="text" value="#a#">
         </cfoutput>

         <input name="sf" type="submit" value="*" onClick="f('bbbb.cfm','windowname')">       
      </form>
    <cfoutput><a href="javascript:g('bbbb.cfm','x','#a#')">open page bbbb</a></cfoutput>
   </body>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2010 Feb 04, 2010

Perhaps, even neater:

function f(nextpg_,nextwin_)
         {
            var _attrs='';
            var _br=navigator.appName;
            document.forms[0].method="post";
            document.forms[0].action=nextpg_;
            document.forms[0].target=nextwin_;

etc., etc

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2010 Feb 04, 2010

document.forms[0].target=nextwin_; fixed it. I'm pretty happy about this. Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2010 Feb 04, 2010
LATEST
document.forms[0].target=nextwin_; fixed it. I'm pretty happy about this. Thanks.

It's all right.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources