Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-16-2004, 06:04 PM   PM User | #1
ScottInTexas
Regular Coder

 
Join Date: Nov 2002
Posts: 567
Thanks: 2
Thanked 4 Times in 4 Posts
ScottInTexas is on a distinguished road
Addressing a text box from javascript

OK, I'm obviously missing something basic about addressing elements on my webpage because I have this problem all the time.

Here is the area of the web page in which the text box resides.
Code:
            <div id="updateDateDiv">
	<input type="text" value="" size="10" id="upDateDate" />
	<input type="button" value="Update" onClick="SetUpdateDate()" />
	Update Date
	</div>
and here is the javascript;
Code:
function SetUpdateDate(){
    var todaysDate = new Date();
	var txtDate = monthName[todaysDate.getMonth()] + " " + todaysDate.getDay() + ", " + todaysDate.getYear();
	document.upDateDate.value=txtDate;
}
This generates an error "upDateDate is null or not an object.

Thanks for your help. I know I'll feel stupid when I see the answer.
__________________
Scott Stewart
Always happy to learn from pros.
ScottInTexas is offline   Reply With Quote
Old 07-16-2004, 06:28 PM   PM User | #2
Frank
Regular Coder

 
Join Date: Dec 2002
Location: Ontario, Canada
Posts: 183
Thanks: 0
Thanked 1 Time in 1 Post
Frank is an unknown quantity at this point
I would suggest you use a form tag and change the "id" attribute to a "name" attribute , and include the form name in the javascript.


So your htm would look like this.
Code:
<html>
<head>
<script type=" type="text/javascript"">
function SetUpdateDate(){
    var todaysDate = new Date();
	var txtDate = monthName[todaysDate.getMonth()] + " " + todaysDate.getDay() + ", " + todaysDate.getYear();
	document.form1.upDateDate.value=txtDate;
}
</script>
<head>
<body>
<form name="form1">


<div id="updateDateDiv">
	<input type="text" value="" size="10" name="upDateDate" />
	<input type="button" value="Update" onClick="SetUpdateDate()" />
	Update Date
</div>

</form>
</body>
</html>
There maybe a better way to do this but this is how I do it.
__________________
if ( atfirst != succeed)
tryagain();
Frank is offline   Reply With Quote
Old 07-16-2004, 09:32 PM   PM User | #3
Basscyst
Smokes a Lot


 
Join Date: Jul 2003
Location: CA, USA
Posts: 1,594
Thanks: 5
Thanked 20 Times in 20 Posts
Basscyst is on a distinguished road
Hello,

Being it is just a snippit of code I would assume you have a form tag. In which case the proper syntax would be:

document.forms[x].elements[x].value (x being the form or element number with in the document or form respectivly)

or

document.formName.FieldName.value

or

document.getElementById('fieldName').value

Basscyst
__________________
Helping to build a bigger box. - Adam Matthews

Last edited by Basscyst; 07-16-2004 at 09:37 PM..
Basscyst is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:48 PM.


Advertisement
Log in to turn off these ads.