Change selected value of drop down list array.

I am createing an attendance management system for a school in PHP and have come into some trouble.

On the registers form, i have an array of drop down lists called "mark" and each ones index is the unique number of the pupil (e.g. "U56546546456").

I need some javascript that enable you to change one drop down list, and apply that change to all the others in the array. A sort of "Master Drop Down List". This is to save teachers time in setting every student to present as they can flood fill all the drop down list with the mark "P".

How can i do this in javascript which i presume is the language i need to use?

Thanks
adamdayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GwynforWebCommented:
not sure exactly how evreything is set up her but this perhaps?

<head>
<script>
function init(){
 studSel=new Array()
 studSel['U56546546456']=document.f1.s1
 studSel['U56546546468']=document.f1.s2
 studSel['U56546546473']=document.f1.s3

}
function setPresent(){
 for (i in studSel) studSel[i].selectedIndex=1
}
</script>
</head>

<body onload="init()">
<p><input type="button" value="set all present" onclick="setPresent()"> </p>
<form name="f1">
  <p><select name="s1" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select> <select name="s2" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select> <select name="s3" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select> </p>
</form>
0
nitrogenxCommented:
I assume you can output the javascript function MasterChanged() using PHP
  <script>
  function MasterChanged()
  {
    document.form1.s1.selectedIndex=
    document.form1.s2.selectedIndex=
    document.form1.s3.selectedIndex=
    document.form1.master.selectedIndex;    
  }
  </script>
    <form id="form1" name="form1">
   
 
  Master:
  <select name="master" onchange="MasterChanged()" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select>
  Student one:
  <select name="s1" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select>
  Student two:
  <select name="s2" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select>
  Student three:
  <select name="s3" size="1">
    <option>-Choose-</option>
    <option>P</option>
    <option>A</option>
  </select>    
    </form>
0
nitrogenxCommented:
i missed the start form tag there:   <form name="form1">
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

adamdayAuthor Commented:
Thanks for the quick replies,

The above code is the way i think i need to solve this proble, however, the register marks drop down lists, are in an array. e.g.

<select name=mark[U894378547353]>
<option ....
</select>
<select name=mark[A234479879499]>
<option ....
</select>

So i tried the javascript:

echo("<script language='javascript'>");
echo("function setpresent() {");
while (!$rs->EOF) {
$student=$rs->Fields("UPN");
echo("document.register.mark['$student->value'].selectedindex=1;");
echo("\n");
$rs->MoveNext();
}
echo("} \n</script>");

The field UPN stands for Unique Pupil Number. "register" is the name of the form.

When i try this, i get an error saying:

'document.register.mark.U43543543543' is null or not an object

How can i fix this

Thanks Again
0
nitrogenxCommented:
its not working because javascript thinks that mark[A234479879499] is refering to an array rather than a form name.  Either change it to mark_A234479879499 or something or replace the

echo("document.register.mark['$student->value'].selectedindex=1;");

with

echo("document.getElementsByName('mark["."$student->value"."]')[0].selectedIndex=1;");
I think thats correct...the javascript line should be rendered as:

document.getElementsByName('mark[U894378547353]')[0].selectedIndex=1;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nitrogenxCommented:
*form element name
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.