Retrieving Form Value

C

Cognizance

I need a solution for the following, if anyone can think of one. :)

I have:
1 form on the page. (no name, no id value set.)
3 hidden form elements named: catalog, vwoidc, oid

!!! I can only include the javascript right after the body tag. The
form is found near the end of the loaded page.


<form action="actionURL" method=post>
<input type=hidden name=catalog value=store>
<input type=hidden name=vwoidc value=69a6e1deb02417250691>
<input type=hidden name=oid value=60323></form>

Everything I've tried needs to have the javascript executed after the
page has been fully loaded.

Thanks in advance!!
 
M

Mick White

Cognizance said:
I need a solution for the following, if anyone can think of one. :)

I have:
1 form on the page. (no name, no id value set.)
3 hidden form elements named: catalog, vwoidc, oid

!!! I can only include the javascript right after the body tag. The
form is found near the end of the loaded page.

<body>
<script type="text/javascript">
onload=function(){ //do stuff with document.forms[0] }
</script>

Mick
 
A

ASM

Cognizance said:
Everything I've tried needs to have the javascript executed after the
page has been fully loaded.

yes of course.
JS can't read or write-in thomething that doesn't yet append
 
R

Randy Webb

ASM said:
yes of course.

No, not of course. JS doesnt need the page fully loaded, it needs what
you are trying to access rendered/loaded.

Create a test page that has 80,000 lines. At the top, right after the
body, add a script block with an alert that does something with the
previous code and you will be surprised that it will indeed read it
before the page has loaded.
 
M

Matt Kruse

Randy said:
No, not of course. JS doesnt need the page fully loaded, it needs what
you are trying to access rendered/loaded.

Is that necessarily true for all browsers?

I remember some version of Netscape in the past that wouldn't expose any
part of the document until it was done loading. So, putting <script> at the
end of the <body> didn't work because you still couldn't access the
contents.

I've always wondered if any specs require that content be made available to
script as soon as it is parsed, or if a browser could choose not to expose
anything to script until everything is loaded.
 
C

Cognizance

I tried Mick's suggestion, and it seems to be the same issue. When I
place the following at the end of the page (just before /body) it will
work:

onload=test();
function test(){
var iName = document.forms[0].elements[0].value;
alert(iName);

However, if it's at the top just after the body tag (where this script
will be included) it will not work.

Randy, I'm not sure I understand your suggestion. I'm not too great
with javascript. Still just getting by. Could you please help clarify?
 
R

Randy Webb

Cognizance said:
I tried Mick's suggestion, and it seems to be the same issue. When I
place the following at the end of the page (just before /body) it will
work:

onload=test();
function test(){
var iName = document.forms[0].elements[0].value;
alert(iName);

It happened to work in a scenario, but it will not always work. The
reason is that you shouldn't have the () on the first test.
You are also missing a } at the end of your function.
It should be:

window.onload = test;

When the browser sees the test() as you have it, it executes the
function right then, not after onload fires.
However, if it's at the top just after the body tag (where this script
will be included) it will not work.

See above.
Randy, I'm not sure I understand your suggestion. I'm not too great
with javascript. Still just getting by. Could you please help clarify?

Try reading the FAQ with regards to posting/quoting.
 
C

Cognizance

Randy said:
It happened to work in a scenario, but it will not always work. The
reason is that you shouldn't have the () on the first test.
You are also missing a } at the end of your function.
It should be:

window.onload = test;

When the browser sees the test() as you have it, it executes the
function right then, not after onload fires.

Sweet. That does the trick!! Thanks!

Try reading the FAQ with regards to posting/quoting.
Are you referring to the FAQ referenced in your sig?
(http://jibbering.com/faq)
 
M

Mick White

Cognizance said:
I tried Mick's suggestion, and it seems to be the same issue. When I
place the following at the end of the page (just before /body) it will
work:

onload=test();
function test(){
var iName = document.forms[0].elements[0].value;
alert(iName);

However, if it's at the top just after the body tag (where this script
will be included) it will not work.


I didn't suggest the stuff above, rather I suggested using an anonymous
function:
<body>
<script type="text/javascript">
onload=function(){alert(document.forms[0].elements[0].value);}
</script>

Mick
 
C

Cognizance

I have another question...

Mick said:
I didn't suggest the stuff above, rather I suggested using an anonymous
function:
<body>
<script type="text/javascript">
onload=function(){alert(document.forms[0].elements[0].value);}
</script>

Mick

Sorry for the confusion, Mick. I was able to get the function to
execute properly. My current script looks like:

<!--
window.onload = getTotal;

function getTotal(){
var oDiv = document.getElementsByTagName("body");
var pBody = oDiv[0];
var bTags = pBody.getElementsByTagName("b");

for (var iii = 0; iii < bTags.length; iii++) {

var cText = bTags[iii].innerHTML;
if (cText.match(/^\d+?\.\d{2}$/)) {
var theValue = cText;
var theOrderID = document.forms[0].oid.value;

var tagstr = "<img
src=\"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato."
+ theOrderID + "/atm1." + theValue + "/\">";
var loadURL =
"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato." +
theOrderID + "/atm1." + theValue;
alert(loadURL);
//document.write(tagstr);
document.load(loadURL);
}
}
}
//-->

Now what I need to do... I need to somehow be able to "hit" the loadURL
that's created. Is there a way to hit an URL without losing the current
document loaded?
 
M

Mick White

Cognizance said:
Sorry for the confusion, Mick. I was able to get the function to
execute properly. My current script looks like:

<!--
window.onload = getTotal;

function getTotal(){
var oDiv = document.getElementsByTagName("body");
var pBody = oDiv[0];
var bTags = pBody.getElementsByTagName("b");

for (var iii = 0; iii < bTags.length; iii++) {

var cText = bTags[iii].innerHTML;
if (cText.match(/^\d+?\.\d{2}$/)) {
var theValue = cText;
var theOrderID = document.forms[0].oid.value;

var tagstr = "<img
src=\"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato."
+ theOrderID + "/atm1." + theValue + "/\">";
var loadURL =
"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato." +
theOrderID + "/atm1." + theValue;
alert(loadURL);
//document.write(tagstr);
document.load(loadURL);
}
}
}
//-->

Now what I need to do... I need to somehow be able to "hit" the loadURL
that's created. Is there a way to hit an URL without losing the current
document loaded?

var w=window.open(loadURL) perhaps?
Mick
 
C

Cognizance

Mick said:
var w=window.open(loadURL) perhaps?
Mick

This seems to want to spawn a new browser window. I want it to be
transparent to the client. I want to keep the initial main page loaded,
and only want to hit the url determined by the javascript, keeping the
main page in view.

Is there a way to hit a URL in the background?
 
C

Cognizance

This seems to want to spawn a new browser window. I want it to be
transparent to the client. I want to keep the initial main page loaded,
and only want to hit the url determined by the javascript, keeping the
main page in view.

Is there a way to hit a URL in the background?

Well gang, I've figured out a way to accomplish what I needed!

<script language="javascript">
<!--
window.onload = getTotal;

function getTotal(){
var oDiv = document.getElementsByTagName("body");
var pBody = oDiv[0];
var bTags = pBody.getElementsByTagName("b");

for (var iii = 0; iii < bTags.length; iii++) {

var cText = bTags[iii].innerHTML;
if (cText.match(/^\d+?\.\d{2}$/)) {
var theValue = cText;
var theOrderID = document.forms[0].oid.value;

var tagstr = "<img
src=\"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato."
+ theOrderID + "/atm1." + theValue + "/\">";
//var loadURL =
"https://switch.atdmt.com/action/adolmb_confirmationpage_7/v3/ato." +
theOrderID + "/atm1." + theValue;
var loadURL =
"https://home.americanapparel.net/test/Sample.jpg?OrderID=" +
theOrderID + "&Total=" + theValue;
alert(loadURL);

Image1= new Image(175,50);
Image1.src = loadURL;

Image2= new Image(175,50);
Image2.src = "https://home.americanapparel.net/60323.gif";
}
}
}
//-->
</script>


Using the preload concept, I'm able to hit the URL in question.

Thanks to those who tried to hook me up with this one! ^^
 
L

Lee

Cognizance said:
<script language="javascript">
<!--
//-->
</script>

I didn't look at your problem (which you seem to have solved),
but the above bits should be replaced by:

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

The comments no longer serve any purpose, since there hasn't
been a browser in use in some time that doesn't understand
the <script> tag.
 
R

RobG

Cognizance said:
Well gang, I've figured out a way to accomplish what I needed!

<script language="javascript">
<!--

What Lee said...
window.onload = getTotal;

function getTotal(){
var oDiv = document.getElementsByTagName("body");
var pBody = oDiv[0];
var bTags = pBody.getElementsByTagName("b");

Why not replace the three lines above with:

var bTags = document.getElementsByTagName('B');


[...]
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top