JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
OK, what is wrong with this? Posted by anglico on 20 Nov 2006 at 4:47 PM
Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.

<html>
<head>
<title>Trying out new shit!</title>

<script type="text/javascript">

var nform = document.forms[0];
var str = nform.tb1.value; //shouldnt this assign the value of
//the text box to the variable?
// Im getting object undefined error

document.write(str.fontcolor=rgb(255,0,0))

</script>
</head>

<body>

<Form action="javascript" method="Post" enctype="text/plain" >

<input type="text" name="tb1" value="" size="10">

</form>

</body>
</html>
Report
Re: OK, what is wrong with this? Posted by zibadian on 20 Nov 2006 at 9:12 PM
: Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.
:
: <html>
: <head>
: <title>Trying out new shit!</title>
:
: <script type="text/javascript">
:
: var nform = document.forms[0];
: var str = nform.tb1.value; //shouldnt this assign the value of
: //the text box to the variable?
: // Im getting object undefined error
:
: document.write(str.fontcolor=rgb(255,0,0))
:
: </script>
: </head>
:
: <body>
:
: <Form action="javascript" method="Post" enctype="text/plain" >
:
: <input type="text" name="tb1" value="" size="10">
:
: </form>
:
: </body>
: </html>
:
Javascript is run as the browser reads it. Thus the assignment is run before the object tb1 is created, hence the unassigned. Solution: create a function in the header, and call that function in the onSubmit() event of the form.
Report
Re: OK, what is wrong with this? Posted by anglico on 21 Nov 2006 at 9:49 AM
: : Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.
: :
: : <html>
: : <head>
: : <title>Trying out new shit!</title>
: :
: : <script type="text/javascript">
: :
: : var nform = document.forms[0];
: : var str = nform.tb1.value; //shouldnt this assign the value of
: : //the text box to the variable?
: : // Im getting object undefined error
: :
: : document.write(str.fontcolor=rgb(255,0,0))
: :
: : </script>
: : </head>
: :
: : <body>
: :
: : <Form action="javascript" method="Post" enctype="text/plain" >
: :
: : <input type="text" name="tb1" value="" size="10">
: :
: : </form>
: :
: : </body>
: : </html>
: :
: Javascript is run as the browser reads it. Thus the assignment is run before the object tb1 is created, hence the unassigned. Solution: create a function in the header, and call that function in the onSubmit() event of the form.
:
Thank you, I tried putting it after the declaration of the tb1 and it still didnt work, so I didnt think that that was the problem. But when I did it your way with a function, it worked, thanks again. You'd have thought starting with c++ that I would have picked that up.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.