hello friends
Hello friends
i have 2 list in my form 1. Employee Type and 2. Designation in first
list (1. Employee Type) i have 3 valuse 2,3,4 ....for designation field
i have wrriten a java script by which when i select employee type 2 it is displaying the corresponding designation.....same way for 2 and 3 , the default selection is 2....
but my problems are
1) when i open this page or refresh the page , the 2 (Teaching faculty) is selected but values are not coming in the second drop down...values are coming only when i select employee type again
2) the selected designation value is not going in the database
my javascript function is addOption(selectList,optionText,optionValue)
Please find the attached php file and image
javascript is not working when refresh form
Moderator: General Moderators
-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
javascript is not working when refresh form
- Attachments
-
- post.zip
- (56.53 KiB) Downloaded 81 times
Last edited by om.bitsian on Sun Sep 27, 2009 6:37 am, edited 1 time in total.
Re: javascript is not working when refresh form
i think it will be better if you just can copy and paste instead of using an attachment.bye
Re: javascript is not working when refresh form
1) on pages onload event call
2) Variable name in your code is $desig not $desg which is used in SQL query
3) Your HTML is invalid
4) You should escape data to prevent SQL injections
Edit: This is my 500 post

Code: Select all
changeList(document.forms.form2.emptyp,document.forms.form2.desg);3) Your HTML is invalid
4) You should escape data to prevent SQL injections
Edit: This is my 500 post
-
om.bitsian
- Forum Commoner
- Posts: 36
- Joined: Wed Sep 09, 2009 4:13 am
Re: javascript is not working when refresh form
sorry kaszu.....but 1st and 2nd points are not working for me
can you explain 3rd and 4th point .....i am new in this techonology
My javascript:
<script language="javascript">
function addOption(selectList,optionText,optionValue)
{
var newOption = document.createElement('OPTION');
newOption.text = optionText;
newOption.value = optionValue;
selectList.options.add(newOption);
}
function changeList(list1,list2) {
list2.length = 0;
if(list1.options[list1.selectedIndex].value == 2)
{
addOption(list2,"ACTD","ACTD"); addOption(list2,"ALEC","ALEC"); addOption(list2,"ASOP","ASOP"); addOption(list2,"ASTP","ASTP");
addOption(list2,"DIRO","DIRO"); addOption(list2,"DLIB","DLIB");addOption(list2,"LECT","LECT"); addOption(list2,"PFAT","PFAT");
addOption(list2,"PROF","PROF");addOption(list2,"TA","TA"); addOption(list2,"VFAC","VFAC"); addOption(list2,"VPRF","VPRF");
}
else if(list1.options[list1.selectedIndex].value == 3)
{
addOption(list2,"ACCO","ACCO"); addOption(list2,"APRG","APRG"); addOption(list2,"ASTR","ASTR"); addOption(list2,"COCH","COCH");
addOption(list2,"CSHR","CSHR"); addOption(list2,"CTOR","CTOR"); addOption(list2,"DRVR","DRVR"); addOption(list2,"DUDT","DUDT");
addOption(list2,"ELER","ELER"); addOption(list2,"FINO","FINO"); addOption(list2,"HSPT","HSPT"); addOption(list2,"JAAT","JAAT");
addOption(list2,"JOAT","JOAT"); addOption(list2,"JTEC","JTEC"); addOption(list2,"LABT","LABT"); addOption(list2,"LBST","LBST");
addOption(list2,"LIST","LIST");addOption(list2,"MEDA","MEDA"); addOption(list2,"MO","MO"); addOption(list2,"OFST","OFST");
addOption(list2,"PA","PA");addOption(list2,"PAST","PAST");addOption(list2,"PRGR","PRGR"); addOption(list2,"SCOP","SCOP");
addOption(list2,"SLAT","SLAT"); addOption(list2,"SMDA","SMDA"); addOption(list2,"SMDO","SMDO"); addOption(list2,"SNRS","SNRS");
addOption(list2,"STCH","STCH");addOption(list2,"SUPV","SUPV"); addOption(list2,"WSPT","WSPT");
}
else if(list1.options[list1.selectedIndex].value == 4)
{
addOption(list2,"ATDT","ATDT");addOption(list2,"CHWK","CHWK");
addOption(list2,"LIDT","LIDT"); addOption(list2,"NRSE","NRSE");
addOption(list2,"OAST","OAST");
}
}
</script>
<select name="emptyp" onChange="changeList(document.forms.form2.emptyp,document.forms.form2.desig)">
Please check the attached image ...when i first time open this page, employee type is selected but value not coming in the designation field
can you explain 3rd and 4th point .....i am new in this techonology
My javascript:
<script language="javascript">
function addOption(selectList,optionText,optionValue)
{
var newOption = document.createElement('OPTION');
newOption.text = optionText;
newOption.value = optionValue;
selectList.options.add(newOption);
}
function changeList(list1,list2) {
list2.length = 0;
if(list1.options[list1.selectedIndex].value == 2)
{
addOption(list2,"ACTD","ACTD"); addOption(list2,"ALEC","ALEC"); addOption(list2,"ASOP","ASOP"); addOption(list2,"ASTP","ASTP");
addOption(list2,"DIRO","DIRO"); addOption(list2,"DLIB","DLIB");addOption(list2,"LECT","LECT"); addOption(list2,"PFAT","PFAT");
addOption(list2,"PROF","PROF");addOption(list2,"TA","TA"); addOption(list2,"VFAC","VFAC"); addOption(list2,"VPRF","VPRF");
}
else if(list1.options[list1.selectedIndex].value == 3)
{
addOption(list2,"ACCO","ACCO"); addOption(list2,"APRG","APRG"); addOption(list2,"ASTR","ASTR"); addOption(list2,"COCH","COCH");
addOption(list2,"CSHR","CSHR"); addOption(list2,"CTOR","CTOR"); addOption(list2,"DRVR","DRVR"); addOption(list2,"DUDT","DUDT");
addOption(list2,"ELER","ELER"); addOption(list2,"FINO","FINO"); addOption(list2,"HSPT","HSPT"); addOption(list2,"JAAT","JAAT");
addOption(list2,"JOAT","JOAT"); addOption(list2,"JTEC","JTEC"); addOption(list2,"LABT","LABT"); addOption(list2,"LBST","LBST");
addOption(list2,"LIST","LIST");addOption(list2,"MEDA","MEDA"); addOption(list2,"MO","MO"); addOption(list2,"OFST","OFST");
addOption(list2,"PA","PA");addOption(list2,"PAST","PAST");addOption(list2,"PRGR","PRGR"); addOption(list2,"SCOP","SCOP");
addOption(list2,"SLAT","SLAT"); addOption(list2,"SMDA","SMDA"); addOption(list2,"SMDO","SMDO"); addOption(list2,"SNRS","SNRS");
addOption(list2,"STCH","STCH");addOption(list2,"SUPV","SUPV"); addOption(list2,"WSPT","WSPT");
}
else if(list1.options[list1.selectedIndex].value == 4)
{
addOption(list2,"ATDT","ATDT");addOption(list2,"CHWK","CHWK");
addOption(list2,"LIDT","LIDT"); addOption(list2,"NRSE","NRSE");
addOption(list2,"OAST","OAST");
}
}
</script>
<select name="emptyp" onChange="changeList(document.forms.form2.emptyp,document.forms.form2.desig)">
Please check the attached image ...when i first time open this page, employee type is selected but value not coming in the designation field
- Attachments
-
- javascript.GIF (55.46 KiB) Viewed 582 times