Description: Create a PSP called Student_Zipcode.psp. This PSP, used to invoke a JavaScript popup window, allowing a user to choose a zip code value for the student she is editing, should be reusable.
1. If the student being edited exists in the database, then that student's zip code value should be pre-selected in the zip code JavaScript pop-up window when the pop-up is invoked.
2. Otherwise, no zip code value should be pre-selected.
Here is an example of a zip code pop-up window with a student's zip code value pre-selected.
Here is an example of a zip code pop-up window where no zip code value is pre-selected.
<%@ page language="PL/SQL" %>
<%@ plsql procedure="student_zipcode" %>
<%@ plsql parameter="p_student_id" type="number" default="null" %>
<%
---------------------------------------------------------
-- FILENAME: student_zipcode.psp
-- FILEDATE: 02.02.2002
-- CREATED BY: Melanie Caffrey
-- DESCRIPTION: Change Zipcode (and City and State)
-- URL: http://local_host/pls/any/student_zipcode
---------------------------------------------------------
%>
<%! CURSOR c_zip IS
SELECT city, state, zip
FROM zipcode
ORDER BY state, city, zip;
v_count INTEGER := 0;
v_zip zipcode.zip%TYPE := NULL;
%>
<% SELECT COUNT(*)
INTO v_count
FROM student
WHERE student_id = p_student_id;
IF v_count > 0
THEN
SELECT zip
INTO v_zip
FROM student
WHERE student_id = p_student_id;
END IF;
%>
<HTML>
<HEAD>
<TITLE>Student Zipcodes</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function chooseZip() {
window.opener.student_personal_form.p_zip.value=document.zip_form.p_newzip.value;
window.close();
}
</SCRIPT>
<%
-- Remember that the code for this JavaScript function
-- MUST be written on one line. Otherwise, your
-- function call with fail.
%>
</HEAD>
<BODY BGCOLOR="pink">
<H2>List of Available Zipcodes With Associated City/State Values</H2>
<FORM NAME="zip_form" ACTION="">
<CENTER><TABLE BORDER="1" BORDERCOLOR="forest green" CELLPADDING=5>
<TR>
<TH ALIGN="center">City, State and Zipcode</TH>
</TR>
<TR>
<TD ALIGN="left"><SELECT SIZE="20" SCROLLBARS="yes" NAME="p_newzip">
<% FOR rec IN c_ZIP
LOOP
IF rec.zip = v_zip
THEN
%>
<OPTION VALUE="<%= rec.zip %>" SELECTED><%= rec.city %>, <%= rec.state %> <%= rec.zip %>
</OPTION>
<% ELSE %>
<OPTION VALUE="<%= rec.zip %>"><%= rec.city %>, <%= rec.state %> <%= rec.zip %>
</OPTION>
<% END IF;
END LOOP;
%>
</SELECT>
</TD>
</TR>
</TABLE></CENTER>
<BR>
<CENTER><INPUT TYPE="button" VALUE="Select Zipcode" onclick="javascript:chooseZip();">
<INPUT TYPE="button" VALUE="Close" onClick="window.close();"></CENTER>
</FORM>
</BODY>
</HTML>