Hidden field two jumps

Discussion in 'Javascript' started by Bill Steele, Oct 6, 2006.

  1. Bill Steele

    Bill Steele Guest

    I want to have a window pop up with a form. When the form is submitted,
    it needs to pass along the URL of the original window. If find on th
    web eight gazillion descriptions of how to pass data from one page to
    another via hidden fields, but not a word about how to pass that data a
    second time.

    I find that

    <SCRIPT LANGUAGE="JavaScript"><!--
    document.write(document.referrer);
    //--></SCRIPT>">

    will write the URL to the page.

    <input type="text" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    document.write(document.referrer);
    //--></SCRIPT>">

    will place the referrer URL in a visible window, so

    <input type="hidden" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    document.write(document.referrer);
    //--></SCRIPT>">

    should place the referrer in the hidden field.

    But in both cases, the form does not pass the value on. It just passes
    "<SCRiPT LANGUAGE="JavaScript..." etc. The browser accepts that as text,
    but not as an element inside a form.

    I also tried using document.write statements to write the entire form.
    The browser doesn't believe it's a form.

    So, how do I create a hidden form field with data from the referring
    window?
     
    Bill Steele, Oct 6, 2006
    #1
    1. Advertising

  2. Bill Steele

    Guest

    It's

    <script type="text/javascript"></script>

    not

    <SCRIPT LANGUAGE="JAVASCRIPT"></SCRIPT>

    That screaming and it's not declaring the type of script...

    Secondly, never use document.write... it's an old school API that's
    only there so your old old old apps don't break.

    Third,

    If you want to put something in a hidden field do this...

    <script type="text/javascript">
    <!--
    window.onload = function(evt) {
    var data;
    data = ''; // whatever
    document.getElementById('hMyData').value = data;
    }
    // -->
    </script>

    <input type="hidden" name="hMyData" id="hMyData" />

    Fourth... you may want to look into server-side scripting (PHP, ASP.NET
    2.0, etc...)

    Bill Steele wrote:
    > I want to have a window pop up with a form. When the form is submitted,
    > it needs to pass along the URL of the original window. If find on th
    > web eight gazillion descriptions of how to pass data from one page to
    > another via hidden fields, but not a word about how to pass that data a
    > second time.
    >
    > I find that
    >
    > <SCRIPT LANGUAGE="JavaScript"><!--
    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > will write the URL to the page.
    >
    > <input type="text" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > will place the referrer URL in a visible window, so
    >
    > <input type="hidden" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > should place the referrer in the hidden field.
    >
    > But in both cases, the form does not pass the value on. It just passes
    > "<SCRiPT LANGUAGE="JavaScript..." etc. The browser accepts that as text,
    > but not as an element inside a form.
    >
    > I also tried using document.write statements to write the entire form.
    > The browser doesn't believe it's a form.
    >
    > So, how do I create a hidden form field with data from the referring
    > window?
     
    , Oct 7, 2006
    #2
    1. Advertising

  3. Bill Steele

    RobG Guest

    Bill Steele wrote:
    > I want to have a window pop up with a form. When the form is submitted,
    > it needs to pass along the URL of the original window. If find on th
    > web eight gazillion descriptions of how to pass data from one page to
    > another via hidden fields, but not a word about how to pass that data a
    > second time.
    >
    > I find that
    >
    > <SCRIPT LANGUAGE="JavaScript"><!--


    The language attribute is deprecated, type is required. Do not use
    HTML comment delimiters inside script elements.

    <script type="text/javascript">
    /* script... */
    </script>


    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > will write the URL to the page.
    >
    > <input type="text" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > will place the referrer URL in a visible window, so


    Not in any browser I have. It appears to me that it's invalid HTML,
    you are assigning the value:

    "<SCRIPT LANGUAGE="

    to the input's value attribute, the rest is junk. Whatever happens in
    your browser is likely the result of error correction - test it in some
    other browsers.


    > <input type="hidden" value= "<SCRIPT LANGUAGE="JavaScript"><!--
    > document.write(document.referrer);
    > //--></SCRIPT>">
    >
    > should place the referrer in the hidden field.


    No, it shouldn't. You can't place a script element inside the tag of
    another element, it's invalid HTML. Script elements are HTML elements,
    they can't be embedded inside the tags of other elements.


    > But in both cases, the form does not pass the value on. It just passes
    > "<SCRiPT LANGUAGE="JavaScript..." etc. The browser accepts that as text,
    > but not as an element inside a form.


    Which is exactly what it should do.


    > I also tried using document.write statements to write the entire form.
    > The browser doesn't believe it's a form.


    Mine does, try something like:

    <script type="text/javascript">
    var ref = document.referer || 'no referrer';
    document.write(
    '<form action="">' +
    '<input type="text" value="' +
    ref + '" name="referrer"></form>'
    );
    </script>


    --
    Rob
     
    RobG, Oct 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Knoop

    Postback jumps to different page

    John Knoop, Jun 27, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    477
    andrei
    Jun 27, 2003
  2. Lenard Gunda
    Replies:
    3
    Views:
    1,273
    =?Utf-8?B?S2FubmFuLlYgW01DU0QubmV0XQ==?=
    Aug 17, 2005
  3. Replies:
    1
    Views:
    319
    Andrew Thompson
    Feb 11, 2005
  4. Jeffrey Baker

    Jumps through a program

    Jeffrey Baker, Nov 19, 2003, in forum: C++
    Replies:
    3
    Views:
    304
    Jeffrey Baker
    Nov 19, 2003
  5. Rick
    Replies:
    3
    Views:
    8,332
    Alexey Smirnov
    Apr 13, 2010
Loading...

Share This Page