Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and Forms

Status
Not open for further replies.

Mezz

MIS
Apr 28, 2002
2
PH
Hi all, i'm very new to programming and was trying to do a webpage with forms and javascript.

I tried submitting some data to another webpage but with javascript, i can't seem to retreive the data correctly. I always get a error saying data or object is null. I wanted to do this in javascript instead of asp. Pls help.

Page 1 :
<html>
<head>
<title>testingt</title>
<SCRIPT LANGUAGE=&quot;Javascript&quot;>
</SCRIPT>

</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<FORM NAME=&quot;testing&quot; ACTION=&quot;test2.htm&quot; METHOD=&quot;POST&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;GYY&quot; VALUE=&quot;1234567890&quot;>
<INPUT TYPE=&quot;submit&quot; value=&quot;Send&quot;>
</FORM>
</body>

</html>

Page 2:
<html>
<head>
<title>Untitled Document</title>
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>
document.write(&quot;hhhhhh&quot;);
doh=document.testing.GYY.value
document.write(&quot;this is a test&quot;+doh);
</SCRIPT>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

</body>
</html>
 
It all boils down to Parent/Child DOM. Here is what your form looks like to the browser:

Parent: Document
Child: Testing

Parent: Testing
Child: GYY

document->testing->GYY

testing is a child of document. document in this case is page1. Once you changed pages, document becomes page2 to the browser.

Since testing is not a child of page2, GYY cannot be a child of testing.

You will have to parse the contents of the form data separately. You can't call on it as if it exists naturally within the page.

Check out this link:


It will explain all the elements of form control with Javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top