Hi Claudio,
I am sorry - I do not have time to explain my code...
I hope by time you will be able to understand it,
cause it will take some time to get used to new
code - take it easy!
Cheers,
Sten Hougaard
EDB Gruppen
Application developer/web-designer
"Pallone, Claudio
[KMR-SPC]" To: "JavaScript HowTo"
<javascript_howto@p...>
<Claudio.Pallone@k... cc:
mrspc.com> Subject: [javascript_h
owto] Re: Name/ID List
03/18/2002 11:20
AM
Please respond to
"JavaScript HowTo"
Hi Sten,
Many thanks for this solution. However, could you please explain to us
how
the code works. In my case, I am trying to learn Javascript and it is v
ery
important to learn the concepts rather than just pasting the code.
So, your explanaiton would be greatly appreciated.
Cheers,
Claudio
Subject: Re: Name/ID List
From: "Sten Hougaard" <STG@e...>
Date: Fri, 15 Mar 2002 09:26:22 +0100
X-Message-Number: 1
Hi
It all depends...: Which browser do you target? for instace...
You might use the DOM tree to build up your data model.
If you insert a target division which is not displayed, then
you can "save" your data here and use the methodes of the
DOM tree to get information for a given employee...
Here is a complete soloution! :-)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>*** Your Title Here ***</TITLE>
<script language=3D"JavaScript">
<!--
function newEmployee(strNumber, strFirstName, strLastName) {
=A0 var targetDiv=A0=A0 =3D document.getElementById('myEmployees');
=A0 var myEmp=A0=A0=A0=A0=A0=A0 =3D document.createElement('div');
=A0 myEmp.id=A0=A0=A0=A0=A0=A0=A0 =3D 'e'+strNumber;
=A0 myEmp.firstName =3D strFirstName;
=A0 myEmp.lastName=A0 =3D strLastName;
=A0 targetDiv.appendChild(myEmp);
}
function init() {
=A0 newEmployee('1', 'Chris R.', ' Thompson')
=A0 newEmployee('2', 'Sten', 'Hougaard')
}
function getInfo(strNumber) {
=A0 var objEmployee =3D document.getElementById('e'+strNumber);
=A0 if (objEmployee) {
=A0=A0 employeeNbr.value=A0 =3D '';
=A0=A0 firstName.value=A0=A0=A0 =3D '';
=A0=A0 lastName.value=A0=A0=A0=A0 =3D '';
=A0=A0 var nbr=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D objEmployee.id.toSt
ring();
=A0=A0 nbr=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D nbr.substr(
1, nbr.length-1)
=A0=A0 employeeNbr.value=A0 =3D nbr;
=A0=A0 firstName.value=A0=A0=A0 =3D objEmployee.firstName;
=A0=A0 lastName.value=A0=A0=A0=A0 =3D objEmployee.lastName;
=A0 } else {
=A0=A0=A0 alert('Employee# '+strNumber+' not found');
=A0 }
}
function add(strNumber) {
=A0 if (employeeNbr.value=3D=3D'') {
=A0=A0=A0 alert('Please enter at least a employee#!')
=A0=A0=A0 return (false)
=A0 }
=A0 var objEmployee =3D document.getElementById('e'+employeeNbr.value);
=A0 var update=A0=A0=A0=A0=A0 =3D false;
=A0 if (objEmployee) {
=A0=A0=A0 if (!confirm('Employee# '+employeeNbr.value+' allready exists
!\nDo you
wish to update data?')) {
=A0=A0=A0=A0=A0 return (false)
=A0=A0=A0 }
=A0=A0=A0 update=A0=A0=A0=A0=A0 =3D true;
=A0 }
=A0 newEmployee(employeeNbr.value, firstName.value, lastName.value)
=A0 alert('Employee# '+employeeNbr.value+((update) ? ' updated' : ' add
ed'));
}
// -->
</script>
</HEAD>
<BODY onload=3D"init()">
<div id=3D"myEmployees" style=3D""></div>
<table border=3D0 cellpadding=3D0 cellspacing=3D0>
<tr>
=A0 <th valign=3Dtop align=3Dright><input type=3D"button" value=3D"Find
" onclick
=3D"getInfo(nbr.value)"></th>
=A0 <td valign=3Dtop><input type=3D"text" size=3D"5" name=3D"nbr" value
=3D"1"></td>
</tr>
<tr>
=A0 <th valign=3Dtop>Employee# </th>
=A0 <td valign=3Dtop><input type=3D"text" size=3D"5" name=3D"employeeNb
r"></td>
</tr>
<tr>
=A0 <th valign=3Dtop>First name</th>
=A0 <td valign=3Dtop><input type=3D"text" name=3D"firstName"></td>
</tr>
<tr>
=A0 <th valign=3Dtop>Last name</th>
=A0 <td valign=3Dtop><input type=3D"text" name=3D"lastName"></td>
</tr>
<tr>
=A0 <th colspan=3D2 valign=3Dtop align=3Dright><input type=3D"button" v
alue=3D"Add"
onclick=3D"add(nbr.value)"></th>
</tr>
</table>
</BODY>
</HTML>
Cheers,
Sten Hougaard
EDB Gruppen
Application developer/web-designer
BMRB International
http://www.bmrb.co.uk +44 (0)20 8566 5000
____________________________________________________________
This message (and any attachment) is intended only for the recipient an
d
may contain confidential and/or privileged material. If you have receiv
ed
this in error, please contact the sender and delete this message
immediately. Disclosure, copying or other action taken in respect of th
is
email or in reliance on it is prohibited. BMRB International Limited
accepts no liability in relation to any personal emails, or content of
any
email which does not directly relate to our business.