Hidden field two jumps

B

Bill Steele

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?
 
A

agapeton

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...)
 
R

RobG

Bill said:
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... */
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top