By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Need help prefilling input field usin JS

P: n/a
Don
I thought I had this figured out, and have been able to do it in PHP on the server, but, how do I
prefill an input field with a cookie value using JavaScript in a client-side page?

Thanks,
Don
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"Don" <no@adr.com> wrote in message
news:tu********************************@4ax.com...
I thought I had this figured out, and have been able to do it in PHP on the server, but, how do I prefill an input field with a cookie value using JavaScript in a client-side page?
Thanks,
Don


Will this help? Watch for word-wrap.

<html>
<head>
<title>coookie.htm</title>
<script type="text/javascript">
function coookie() {
document.getElementById("data").value = document.cookie;
}
</script>
</head>
<body onload="coookie()">
<form>
<input type="text" name="data" size="100">
</form>
</body>
</html>
Jul 23 '05 #2

P: n/a
Don
On Mon, 20 Dec 2004 16:37:40 GMT, "McKirahan" <Ne**@McKirahan.com> wrote:
"Don" <no@adr.com> wrote in message
news:tu********************************@4ax.com.. .
I thought I had this figured out, and have been able to do it in PHP on

the server, but, how do I
prefill an input field with a cookie value using JavaScript in a

client-side page?

Thanks,
Don


Will this help? Watch for word-wrap.

<html>
<head>
<title>coookie.htm</title>
<script type="text/javascript">
function coookie() {
document.getElementById("data").value = document.cookie;
}
</script>
</head>
<body onload="coookie()">
<form>
<input type="text" name="data" size="100">
</form>
</body>
</html>

Thanks McKirahan. I'll give it a try. It sure is nice knowing you're out there to help out.
Thanks much, and have a Happy Holiday Season.
Don
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Jul 23 '05 #3

P: n/a
Don
On Mon, 20 Dec 2004 16:37:40 GMT, "McKirahan" <Ne**@McKirahan.com> wrote:
"Don" <no@adr.com> wrote in message
news:tu********************************@4ax.com.. .
I thought I had this figured out, and have been able to do it in PHP on

the server, but, how do I
prefill an input field with a cookie value using JavaScript in a

client-side page?

Thanks,
Don


Will this help? Watch for word-wrap.

<html>
<head>
<title>coookie.htm</title>
<script type="text/javascript">
function coookie() {
document.getElementById("data").value = document.cookie;
}
</script>
</head>
<body onload="coookie()">
<form>
<input type="text" name="data" size="100">
</form>
</body>
</html>

McKirahan,

I tried your suggestion, and it works just great with IE. But can't seem to get any prefill with
Netscape. Doesn't Netscape allow prefills?

Thanks,
Don
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Jul 23 '05 #4

P: n/a
"Don" <no@adr.com> wrote in message
news:gf********************************@4ax.com...

[snip]
McKirahan,

I tried your suggestion, and it works just great with IE. But can't seem to get any prefill with Netscape. Doesn't Netscape allow prefills?

Thanks,
Don


Change
document.getElementById("data").value = what;
to
document.forms[0].data.value = what;

What version of NS are you running?

I don't know when getElementById() was supported.
Jul 23 '05 #5

P: n/a
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:8wTxd.233149$V41.22654@attbi_s52...
"Don" <no@adr.com> wrote in message
news:gf********************************@4ax.com...

[snip]
McKirahan,

I tried your suggestion, and it works just great with IE. But can't
seem to get any prefill with
Netscape. Doesn't Netscape allow prefills?

Thanks,
Don


Change
document.getElementById("data").value = what;
to
document.forms[0].data.value = what;

What version of NS are you running?

I don't know when getElementById() was supported.


I meant, change
document.getElementById("data").value = document.cookie;
to
document.forms[0].data.value = document.cookie;
Jul 23 '05 #6

P: n/a
On Tue, 21 Dec 2004 11:09:56 GMT, McKirahan <Ne**@McKirahan.com> wrote:

[snip]

[To Don:]
What version of NS are you running?


It wouldn't matter.

As I've said to you a couple of times in the past, document.getElementById
is *NOT* - I repeat, *NOT* - allowed to return elements that have a
matching name. IE, if you haven't noticed by now, is not a browser that
should be used for primary testing of Web documents. It's too lenient - a
very bad thing in my opinion.

If you need to retrieve elements document-wide based on their names, use
the document.getElementsByName method. Alternatively, use the forms and
elements collection, which I think is always preferable when accessing a
form control within a form.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7

P: n/a
Don
On Tue, 21 Dec 2004 11:59:20 GMT, "McKirahan" <Ne**@McKirahan.com> wrote:
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:8wTxd.233149$V41.22654@attbi_s52...
"Don" <no@adr.com> wrote in message
news:gf********************************@4ax.com...

[snip]
> McKirahan,
>
> I tried your suggestion, and it works just great with IE. But can't

seem
to get any prefill with
> Netscape. Doesn't Netscape allow prefills?
>
> Thanks,
> Don


Change
document.getElementById("data").value = what;
to
document.forms[0].data.value = what;

What version of NS are you running?

I don't know when getElementById() was supported.


I meant, change
document.getElementById("data").value = document.cookie;
to
document.forms[0].data.value = document.cookie;

Great! That did it. Thanks much McKirahan.
Don
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Jul 23 '05 #8

P: n/a
Don
BTW, I'm running Netscape 7.2
Don
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Jul 23 '05 #9

P: n/a
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsjcz14iyx13kvk@atlantis...
On Tue, 21 Dec 2004 11:09:56 GMT, McKirahan <Ne**@McKirahan.com> wrote:

[snip]

[To Don:]
What version of NS are you running?


It wouldn't matter.

As I've said to you a couple of times in the past, document.getElementById
is *NOT* - I repeat, *NOT* - allowed to return elements that have a
matching name. IE, if you haven't noticed by now, is not a browser that
should be used for primary testing of Web documents. It's too lenient - a
very bad thing in my opinion.

If you need to retrieve elements document-wide based on their names, use
the document.getElementsByName method. Alternatively, use the forms and
elements collection, which I think is always preferable when accessing a
form control within a form.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


Mike,

The rules keep changing and it's hard to keep up.

Can you point me to some good documentation regarding
document.getElementsById
and
document.getElementsByName
usage? Thanks.
Jul 23 '05 #10

P: n/a
On Tue, 21 Dec 2004 14:25:48 GMT, McKirahan <Ne**@McKirahan.com> wrote:

[snip]
Can you point me to some good documentation
I find that the W3C DOM specifications
<URL:http://www.w3.org/DOM/DOMTR.html#DOML2> are fine. It just takes a
little while to get used to how the information is presented. Navigation,
especially within the PDFs, can be a pain, though. Alternatively, the
(incomplete) documentation provided by Mozilla
<URL:http://www.mozilla.org/docs/dom/domref> also gives an accurate
account of the specification and is slightly more readable.

I'm afraid that as I've never needed to read other sources, I can't give
you any. There's always Google.

The only other suggestion is to use another browser if you can. Both
Mozilla (Suite and Firefox) and Opera are free (and quite small), and
conform to the various specifications much better than IE probably ever
will[1].
regarding
document.getElementsById
<URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId>
<URL:http://www.mozilla.org/docs/dom/domref/dom_doc_ref48.html#1025944>
and
document.getElementsByName


<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259>
<URL:http://www.mozilla.org/docs/dom/domref/dom_doc_ref49.html#1025973>

[snip]

Mike
[1] After all, now that it's introduced erroneous behaviour that I have no
doubt authors have used (and will continue to), Microsoft will have to
supporting it in future versions.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.