Wrox Programmer Forums
|
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
 
Old February 28th, 2007, 08:28 PM
Registered User
 
Join Date: Feb 2007
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..


 
Old March 1st, 2007, 03:21 AM
Friend of Wrox
 
Join Date: Oct 2004
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
 
Old March 1st, 2007, 04:55 AM
Registered User
 
Join Date: Feb 2007
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





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





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