473,387 Members | 1,465 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,387 software developers and data experts.

Do I need javascript to pre-populate a form field?

Greetings.
I know not one word of Javascript and wondered if there was
an easy way to pre-populate a form field in a similar manner to
populating an eMail 'subject' field? -
The following populates the subject field in an eMail:
a href="mailto:me@anwhere.com?subject=USER ID 12345

How can I populate the first field of a form (or can I?) with the
same information - i.e. the USER ID located on the HTML page
calling the form?

Any help appreciated
Aug 24 '06 #1
5 3626
Hi,

Richard Rosser wrote:
Greetings.
I know not one word of Javascript and wondered if there was
an easy way to pre-populate a form field in a similar manner to
populating an eMail 'subject' field? -
The following populates the subject field in an eMail:
a href="mailto:me@anwhere.com?subject=USER ID 12345
This is not standard, and you have no guarantee that it will work
correctly...

How can I populate the first field of a form (or can I?) with the
same information - i.e. the USER ID located on the HTML page
calling the form?

Any help appreciated
Using HTML:

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

Using javascript:

document.getElementById( "tfUserId" ).value = "USERID";
This code will throw an error if tfUserId doesn't exist, so a better
code would be:

if ( document.getElementById ) // This checks if the feature exists
{
var nField = document.getElementById( "tfUserId" );
if ( nField != null
&& nField.value != null )
{
nField.value = "USERID";
}
else
{
// No such field, handle error
}
}
else
{
// Browser doesn't support document.getElementById
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 24 '06 #2
Laurent Bugnion wrote:
<snip>
Using HTML:

<input type="text" id="tfUserId" name="tfUserId" value="USERID" />
^

If this is HTML what is that slash doing at the end of the INPUT tag?

Richard.

Aug 24 '06 #3

Richard Cornford wrote:
Laurent Bugnion wrote:
<snip>
Using HTML:

<input type="text" id="tfUserId" name="tfUserId" value="USERID" />
^

If this is HTML what is that slash doing at the end of the INPUT tag?
Stop it. You're going to confuse the newbies.
>
Richard.
Aug 24 '06 #4
Tom Cole wrote:
Richard Cornford wrote:
>Laurent Bugnion wrote:
<snip>
>>Using HTML:

<input type="text" id="tfUserId" name="tfUserId" value="USERID" />
^

If this is HTML what is that slash doing at the end of the INPUT tag?

Stop it. You're going to confuse the newbies.
I am not the one posting XHTML mark-up and labelling it HTML.

Richard.

Aug 24 '06 #5
Hi,

Richard Cornford wrote:
Laurent Bugnion wrote:
<snip>
>Using HTML:

<input type="text" id="tfUserId" name="tfUserId" value="USERID" />
^

If this is HTML what is that slash doing at the end of the INPUT tag?

Richard.
Do you eat a validator for breakfast every morning? ;-)

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but...
4
by: Fabian | last post by:
I have a three tier nested array, used to define a map for a javascript game, and can be edited within the web page. Is there a way I can generate a visible copy of this array that I can then c&p...
4
by: Kent Feiler | last post by:
As an old-time C programmer, I'm used to placing program documentation in the program. No problem there since it all goes away when the executable is created. Using the same technique in...
17
by: Ian | last post by:
Hi there, Can anybody tell me where I can find a standards documents like you have in c#. I am trying to write javascript and would like to know what standards are i.e. Where to put the...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
1
by: Jarrod Hyder | last post by:
Ok, I wrote my own weblog and I'm working on the web interface for adding/editing my posts. I decided to add a little preview button...when the button is clicked it is suppose to open a pop-up...
4
by: beachlover | last post by:
Hi i am a novice to JavaScript - and have started learning it using online study material and a couple of books - slowly i am getting into practicing it at my workplace (after work hours) -...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: kpmassey | last post by:
I am trying to use wget to retrieve web pages like this: http://www.michigan-football.com/s/2006/cascades.htm Visit it and view source to see the obfuscated javascript. Is there any tool to...
1
by: vocalise | last post by:
The title probably isn't very clear, but I haven't been able to find this problem (or I must be having problems figuring out which search strings to use) so I apologize if this has been addressed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.