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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    552
    andrei
    Jun 27, 2003
  2. Microsoft_Public

    Javascript two fields merged to one hidden field

    Microsoft_Public, Dec 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    755
    Karl Seguin
    Dec 14, 2005
  3. Rick
    Replies:
    3
    Views:
    9,940
    Alexey Smirnov
    Apr 13, 2010
  4. GavMc
    Replies:
    4
    Views:
    553
    Evertjan.
    Sep 22, 2005
  5. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    311
  6. Roy Adams
    Replies:
    3
    Views:
    418
    Dr John Stockton
    Dec 21, 2004
  7. Sound
    Replies:
    2
    Views:
    719
    Randy Webb
    Sep 28, 2006
  8. jr
    Replies:
    3
    Views:
    667
Loading...