Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2007, 08:28 PM
Registered User
 
Join Date: Feb 2007
Location: Melbourne, vic, Australia.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default storing user input

how do i store user input in a variable

var myString = document.form1.textfield.value;

when i alert(myString)

undefined keeps poping up

but when i do it this way


var myString = document.form1.textfield.value;

alert(document.form1.textfield.value)

it will tell me what the answer

or do i have to create a function to keep the reference short..


Reply With Quote
  #2 (permalink)  
Old March 1st, 2007, 03:21 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii brainchild!!

hope this will help you

**********ErrorCode.html**************
<script>
var myString = document.form1.textfield.value;
alert(myString)
</script>
<form name=form1>
<input type=text name=textfield>
</form>
Reason-since contents are rendered from top to bottom ,at the line var myString = document.form1.textfield.value;
script is looking for form1 and textfield which are not rendered at the time.it gives the error


**********Solution1.html**************
<script>
function callme()
{
var myString = document.form1.textfield.value;
alert(myString)
}
</script>
<form name=form1>
<input type=text name=textfield>
<input type=button name=btnName value="call" onclick="callme()">
</form>


**********Solution2.html**************

<form name=form1>
<input type=text name=textfield>
</form>
<script>
var myString = document.form1.textfield.value;
alert(myString)
</script>
Reason-No problem , since form and text field already rendered ,no problem to call at the end


Cheers :)

vinod
Reply With Quote
  #3 (permalink)  
Old March 1st, 2007, 04:55 AM
Registered User
 
Join Date: Feb 2007
Location: Melbourne, vic, Australia.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your help

Quote:
quote:Originally posted by vinod_yadav1919
 Hii brainchild!!

hope this will help you

**********ErrorCode.html**************
<script>
var myString = document.form1.textfield.value;
alert(myString)
</script>
<form name=form1>
<input type=text name=textfield>
</form>
Reason-since contents are rendered from top to bottom ,at the line var myString = document.form1.textfield.value;
script is looking for form1 and textfield which are not rendered at the time.it gives the error


**********Solution1.html**************
<script>
function callme()
{
var myString = document.form1.textfield.value;
alert(myString)
}
</script>
<form name=form1>
<input type=text name=textfield>
<input type=button name=btnName value="call" onclick="callme()">
</form>


**********Solution2.html**************

<form name=form1>
<input type=text name=textfield>
</form>
<script>
var myString = document.form1.textfield.value;
alert(myString)
</script>
Reason-No problem , since form and text field already rendered ,no problem to call at the end


Cheers :)

vinod
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoding User Input tectrix BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 February 6th, 2008 06:58 AM
Displaying user input macrocosm Beginning PHP 3 June 15th, 2006 09:30 PM
Examples of storing user info from db in profiles? bpdsmark ASP.NET 2.0 Basics 0 March 11th, 2006 03:13 PM
Validating user input stu9820 VB.NET 2002/2003 Basics 2 January 15th, 2004 12:51 PM



All times are GMT -4. The time now is 07:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.