value from getElementById()

D

DrKen

I coded the function below:
<script type="text/javascript">
function createCookie(name,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else
var expires = "";

var value = document.getElementById("USERID");
var idMessage = "The user id is: " + value;
alert(idMessage);
document.cookie = name+"="+value+expires+"; path=/";
return false;
}


</script>

I have this in my HTML:

<input type="text" name="USERID" id="USERID"/>

When I submit the page in Firefox, I get this on the alert dialog box:
The user id is: [object HTMLInputElement]
I expected to get the contents of USERID back. Why didn't that work?
Thanks.

Ken
 
D

Dr.Kral

I coded the function below:
<script type="text/javascript">
function createCookie(name,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else
var expires = "";

var value = document.getElementById("USERID");

Perhaps you might specify a property to get.
var idMessage = "The user id is: " + value;
alert(idMessage);
document.cookie = name+"="+value+expires+"; path=/";
return false;
}


</script>

I have this in my HTML:

<input type="text" name="USERID" id="USERID"/>

When I submit the page in Firefox, I get this on the alert dialog box:
The user id is: [object HTMLInputElement]
I expected to get the contents of USERID back. Why didn't that work?

It did exactly what you told it to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top