473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Need help prefilling input field usin JS

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
10 2245
"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
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
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
"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
"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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
5
by: J. J. Cale | last post by:
Little astrology program has 2 text input boxes for birth dates. There are 3 selects for day month year that will supply output to whichever text input had the focus last. If the user picks from...
4
by: Adrienne | last post by:
I am the first to admit that I know bupkis about javascript, except that sometimes I need it to do something client side that I can't do server side. Anyway, here's my problem: <input...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
5
by: sourabh | last post by:
Hi I have a basic qus. I am writing a middle-tier component. I have constructor which takes 3 inputs, here's how it looks internal ClassName(Database dbToUse, Int64 pk,DateTime Date) { } ...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
4
by: Paul David Buchan | last post by:
Hello, I'm attempting to write a program to read in database files (.dbf). When I do it all as a single procedure in main, everything works. However, what I really want, is to pass the database...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.