[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

Javascript to autopopulate field based on reference field

I need to use a javascript to autopopulate a field in the student information system, PowerSchool.  The idea is to look at the grade level and populate the graduation year.  The field names are [01]grade_level and [01]graduation_year.  The vales are:
0=2020; 1=2019; 2=2018; 3=2017; 4=2016; 5=2015; 6=2014; 7=2013; 8=2012; 9=2011; 10=2010; 11=2009; 12=2008; 13=0000.
Does anyone have an idea for me?  

0
mlwoods
Asked:
mlwoods
  • 4
  • 2
1 Solution
 
ravs120499Commented:
Is PowerSchool is a 3rd party software? Do you have source code / is it a Javascript application? And why do you need to use Javascript for the solution - won't any other solution do?

If the app is not written in HTML/Javascript, and you don't have source code, then you can use some screen-scraping technology (Tcl/Tk) or a regression test tool like Winrunner to grab the field and then plug it into your screen.
0
 
mlwoodsAuthor Commented:
It is written in HTML/Javascript.  The source code for the page follows:
<html>
<!-- non framed -->
<head>
<title>Enroll New Student</title>
~[wc:commonscripts]
<link href="/images/powerschool.css" rel="stylesheet">
</head>

<body marginwidth=12 marginheight=12 topmargin=12 leftmargin=12 bgcolor="#ffffff">

<form action="checkduplicatestudents.html" method="POST">
~[wc:admin_header]<!-- breadcrumb start --><a href="/admin/home.html" target="_top">Start Page</a> &gt; <a href="/admin/functions.html" target="_top">Special Functions</a> &gt; Enroll New Student<!-- breadcrumb end -->~[wc:admin_navigation]

<!-- start of title -->
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="header">Enroll New Student</td>
</tr>
</table>
<br><br>
<!-- end of title -->

<!-- start of content and bounding box -->
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="2" background="/images/bond_3000_top.gif" align="right"><img src="/images/bound_box_top_right1.gif" width="15" height="9" alt="" border="0"></td>
<td width="25"><img src="/images/bound_box_top_right2.gif" width="25" height="9" alt="" border="0"></td>
</tr>
<tr>
<td width="23" background="/images/bond_box_left_edge.gif"><img src="/images/spacer.gif" width="23" height="1"></td>
<td>

<table border="0" cellspacing="0" cellpadding="4">
<tr bgcolor="#edf3fe">
<td class="bold">Student's Name<br>(Last, First MI)</td>
<td><input type="text" name="last" value="" size="17" maxlength="20">, <input type="text" name="first" value="" size="17" maxlength="20"> <input type="text" name="middle" value="" size="15" maxlength="15"></td>
</tr>
<tr>
<td class="bold">Student number</td>
<td><input type="text" name="student_number" value="" size="12"> (If blank, system will assign)</td>
</tr>
<tr bgcolor="#edf3fe">
<td class="bold">Social Security Number</td>
<td><input type="text" name="SSN" value="" size="17"></td>
</tr>
<tr>
<td class="bold">Phone Number</td>
<td><input type="text" name="Phone" value="" size="17"></td>
</tr>
<tr bgcolor="#edf3fe">
<td class="bold">Enrollment date</td>
<td><input type="text" name="entrydate" value="~[short.date]" size="11" onChange="checkDates('entrydate');"></td>
</tr>
<tr>
<td class="bold">Entry Code</td>
<td>~[custompopup.entrycodes.lists.entrycodes]</td>
</tr>
<tr bgcolor="#edf3fe">
<td class="bold">Full-Time Equivalency</td>
<td>~[if.district.office]FTE selection can only occur within a school.[else]~[custompopup;name=fteid;list=att_ftegetlist][/if.district.office]</td>
</tr>
<tr>
<td class="bold">Grade Level</td>
<td>~[custompopup;name=grade_level;list=gradelevels]</td>
</tr>
<tr bgcolor="#edf3fe">
<td class="bold">Graduation Year </td>
<td><input name="[01]graduation_year" type="text" id="[01]graduation_year"></td>
</tr>
<tr>
<td class="bold"><a href="/admin/districts/" target="_top">District of Residence</a></td>
<td>~[custompopup;name=districtofresidence;list=lists.districts]</td>
</tr>
<tr bgcolor="#edf3fe">
<td class="bold">Fee Exemption Status</td>
<td><select name="Fee_Exemption_Status"><option value="0">Student Not Exempted<option value="1">Student Exempted from Course Fees<option value="2">Student Exempted from School Fees<option value="3">Student Exempted from All Fees</select></td>
</tr>
<tr>
<td class="bold">School</td>
<td>~[schoolname]</td>
</tr>
<!-- Start insert state specific log information -->
~[x:insertfile;state/newstudent~[displaypref:districtstate].html]
<!-- End insert state specific log information -->
</table>
<br>

</td>
<td width="25" background="/images/bond_box_right_edge.gif"><img src="/images/spacer.gif" width="25" height="1"></td>
</tr>
<tr>
<td colspan="2" background="/images/bond_3000_bot.gif" align="right"><img src="/images/bound_box_bot_right1.gif" width="15" height="12" alt="" border="0"></td>
<td width="25"><img src="/images/bound_box_bot_right2.gif" width="25" height="12" alt="" border="0"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="hidden" name="ac" value="eEnrollCheckDup"><input type="hidden" name="dupchecktype" value="enroll"><input type="hidden" name="doftevalidation">~[submitbutton]</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<!-- end of content of bounding box -->

~[wc:admin_footer]
</form>

</body>
</html><!-- non framed -->
0
 
BraveBrainCommented:
This example will get the current year and calculate the graduation years.
You will probably want to uncomment the second
var thisYear = ...
and set the year server side.

<script language="JavaScript">
<!--
    var thisYear = new Date().getFullYear();
//    var thisYear = 2007; // uncomment this to nevermind the automatic year calculation
    var gradeYears = new Array();
    for (var i = 0; i < 13; i++) {
      gradeYears.push(thisYear+i);
    }
    gradeYears.push('0000');
    function setGradeYear() {
      var grade = document.forms['form1'].elements['[01]grade_level'].value;
      if (isNaN(grade) || (void(gradeYears[grade]) == gradeYears[grade])) {
        return false;
      }
      document.forms['form1'].elements['[01]graduation_year'].value = gradeYears[grade];
      return true;
    }
//-->
</script>
 <form name="form1">
  Grade level: <input type="text" name="[01]grade_level" size="4" onkeyup="setGradeYear()" /><br />
  Graduation year: <input type="text" name="[01]graduation_year" size="4" />
 </form>

I take it form your code that the grade level will be set through select/options tags?
If that one starts with grade lvl 0 simply change
var grade = document.forms['form1'].elements['[01]grade_level'].value;
to
var grade = document.forms['form1'].elements['[01]grade_level'].selectedIndex;

and since you don't have a form name you can change
document.forms['form1']..
to
document.forms[0]...
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!

 
BraveBrainCommented:
If you run into problems I'd like to see the generated code from
<td class="bold">Grade Level</td>
<td>~[custompopup;name=grade_level;list=gradelevels]</td>

(as in the code from View Source in the browser)
0
 
BraveBrainCommented:
oh, and since you're probably using a select to pick grade level the
onkeyup="setGradeYear()"
should be either
onchange or onclick

In cases of reloaded page the function should also be called when the document is loaded, i.e.:
<body marginwidth=12 marginheight=12 topmargin=12 leftmargin=12 bgcolor="#ffffff" onload="setGradeYear()">
0
 
mlwoodsAuthor Commented:
Thanks...I'll give it a try and get back to you.
0
 
BraveBrainCommented:
Ooops. I forgot a very important line in that code, before the gradeYears.push('0000') line.
Change this:
    gradeYears.push('0000');
to this:
    gradeYears = gradeYears.reverse();
    gradeYears.push('0000');

Otherwise the array is in the wrong order and will let the 1st grade graduate many years before the 12th grade ^^
0

Featured Post

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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now