Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change selected value of drop down list array.

Posted on 2004-10-24
6
Medium Priority
?
22,340 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:adamday
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12395994
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
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12396424
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
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12396429
i missed the start form tag there:   <form name="form1">
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:adamday
ID: 12402459
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
 
LVL 3

Accepted Solution

by:
nitrogenx earned 2000 total points
ID: 12404624
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
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12404640
*form element name
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question