Question : Populate text box based on drop down selection?

If a user selects a certain program type, I'd like the Program date text box to autopopulate with the desired date.  Can I do this in the switch statement I have.  The text box is ref17val1.  I'm calling the function onchange in the progrtype which calls the switch statement, I want to autopoulate the text box with the program date.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
<?PHP
include("../../campuslife/library/inc/_app_space.php");
require("../../lib/inc/hostconfig.php");
require("../../lib/inc/siteconfig.php");

opendatabase($dbc,$dbprefix);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US">
<head>
<title><?= $sitetitle ?> - Professional Development Registration</title>
<?PHP require("../../lib/inc/meta.php"); ?>
<link type="text/css" rel="stylesheet" href="/lib/css/screen/layout.css" media="screen" />
<link type="text/css" rel="stylesheet" href="/lib/css/screen/content.css" media="screen" />
<link type="text/css" rel="stylesheet" href="/lib/css/screen/theme.css" media="screen" />
<link type="text/css" rel="stylesheet" href="/lib/css/print/all.css" media="print" />
<script type="text/javascript" src="/lib/js/common.js"></script>
<script language="javascript">
var defaultRegistrationType = 0;
var selectedRegistrationType;

function setItemCode(userChoice) {
	
	document.poppedLayer1 = eval('document.getElementById("disc-code1")');
	document.poppedLayer2 = eval('document.getElementById("disc-code2")');
	
	switch(userChoice){
	case "":
			
		document.pdreg.itemcode1.value="";
		document.pdreg.amount1.value="";
		document.poppedLayer1.style.visibility = "hidden";
		document.poppedLayer2.style.visibility = "hidden";
		break;	
	case "CPLP course registration: $1065":
		document.pdreg.itemcode1.value="NT-LT101";
		document.pdreg.amount1.value="$1065";
		document.progDate.value="DATE";
		document.poppedLayer1.style.visibility = "hidden";
		document.poppedLayer2.style.visibility = "hidden";
		break;	
	case "CPLP course early-registration: $1015 *":
		document.pdreg.itemcode1.value="NT-LT101DIS";
		document.pdreg.amount1.value="$1015";
		document.poppedLayer1.style.visibility = "hidden";
		document.poppedLayer2.style.visibility = "hidden";
		break;	
/*	case "Project Leadership Forum - Early Bird Reg: $325":
		//HU Flash Film Fest – Early Bird Conference Pass
		//document.pdreg.itemcode1.value="NT-LT101";
		//document.pdreg.amount1.value="$1065";
		document.pdreg.itemcode1.value="PLF-001";
		document.pdreg.amount1.value="$325";
		break;*/
/*	case "Project Leadership Forum - Early Bird Reg PMI: $295":
		document.pdreg.itemcode1.value="PLF-002";
		document.pdreg.amount1.value="$295";
		document.poppedLayer1.style.visibility = "visible";
		document.poppedLayer2.style.visibility = "visible";
		break;
	case "Project Leadership Forum - Registration: $425":
		document.pdreg.itemcode1.value="PLF-003";
		document.pdreg.amount1.value="$425";
		break;*/
	case "HACCP Manager 2-day: $695":
		document.pdreg.itemcode1.value="NT-HACCP";
		document.pdreg.amount1.value="$695";
		document.poppedLayer1.style.visibility = "hidden";
		document.poppedLayer2.style.visibility = "hidden";
		break;
	case "Implementing SQF – 2-day: $600":
		document.pdreg.itemcode1.value="NT-SQF";
		document.pdreg.amount1.value="$600";
		document.poppedLayer1.style.visibility = "hidden";
		document.poppedLayer2.style.visibility = "hidden";
		break;
	case "HACCP Manager 2-day govt, acad, sanit, disct: $395":
		document.pdreg.itemcode1.value="NT-HACCPD";
		document.pdreg.amount1.value="$395";
		document.poppedLayer1.style.visibility = "visible";
		document.poppedLayer2.style.visibility = "visible";
		break;
/*	case "Project Leadership Forum - Registration PMI: $395":
		document.pdreg.itemcode1.value="PLF-004";
		document.pdreg.amount1.value="$395";
		document.poppedLayer1.style.visibility = "visible";
		document.poppedLayer2.style.visibility = "visible";
		break;*/
			
	}
	
}

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform){
	
	with (thisform)
	{
		if(dummyfield.value.length > 1) {
			alert("There is a problem with the form, your data cannot be submitted at this time!");
			return false;
		} 
		
		  if (validate_email(ref11val1,"Not a valid e-mail address!")==false)
			{ref11val1.focus();return false;}
		  if (validate_required(ref1val1,"Please provide information for all the required fields!")==false)
			{ref1val1.focus();return false;}
		  if (validate_required(ref2val1,"Please provide information for all the required fields!")==false)
			{ref2val1.focus();return false;}
		  if (validate_required(ref7val1,"Please provide information for all the required fields!")==false)
			{ref7val1.focus();return false;}
		  if (validate_required(ref9val1,"Please provide information for all the required fields!")==false)
			{ref9val1.focus();return false;}
		  if (validate_required(ref13val1,"Please provide information for all the required fields!")==false)
			{ref13val1.focus();return false;}
		  if (validate_required(ref10val1,"Please provide information for all the required fields!")==false)
			{ref10val1.focus();return false;}
		  if (validate_required(ref14val1,"Please provide information for all the required fields!")==false)
			{ref14val1.focus();return false;}
		  if (validate_required(ref15val1,"Please provide information for all the required fields!")==false)
			{ref15val1.focus();return false;}
		  if (validate_required(ref16val1,"Please provide information for all the required fields!")==false)
			{ref16val1.focus();return false;}
		  if (validate_required(ref17val1,"Please provide information for all the required fields!")==false)
			{ref17val1.focus();return false;}
		  if (validate_required(ref18val1,"Please provide information for all the required fields!")==false)
			{ref18val1.focus();return false;}
		  if (ref6val1.value=="" && ref5val1.value=="") {
			validate_required(ref5val1,"Please provide informaiton for all the required fields!");
			ref5val1.focus();
			return false; }
		  if (ref15val1.value=="Other" && ref12val1.value==""){
			validate_required(ref12val1,"Please provide information for the Other field!");
			ref12val1.focus();
			return false;
		  }
	}
	
}
</script>
</head>
<body id="b_academics">
<?PHP require("../../lib/inc/header1.php"); ?>
<?PHP include("../../lib/inc/left/nav.php"); ?>
<?PHP require("../../lib/inc/header2.php"); ?>
<?PHP include("../../lib/inc/left/callouts.php"); ?>
<?PHP require("../../lib/inc/header3.php"); ?>
<?PHP require("../../lib/inc/header4.php"); ?>
<?PHP
$selectedState = "PA";
$selectedAddressType = "Work Address";
   
    function showOptionsDrop($array, $active, $echo=true){
        $string = '';

        foreach($array as $k => $v){
            $s = ($active == $k)? ' selected="selected"' : '';
            $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";     
        }

        if($echo)   echo $string;
        else        return $string;
    }
   
   	$states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"District Of Columbia",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa",  'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
	
	$addresstype_arr = array('Work Address'=>"Work Address",'Home Address'=>"Home Address");
	
	$source_arr = array('Harrisburg University email'=>"Harrisburg University email",'Email from Professional Assocation'=>"Email from Professional Assocation",'Friend or Colleague'=>"Friend or Colleague",'Social Network'=>"Social Network",'Web search'=>"Web search",'Mailing'=>"Mailing",'News Post'=>"News Post",'Other'=>"Other");
	
	$program_arr = array('CPLP'=>"CPLP",'HACCP Manager – 2-day'=>"HACCP Manager – 2-day",'Implementing SQF – 2-day'=>"Implementing SQF – 2-day");
	
	$programdate_arr = array('Sept 15 – Oct 27, 2010'=>"Sept 15 – Oct 27, 2010",'October 5 & 6, 2010'=>"October 5 & 6, 2010",'October 28 & 29, 2010'=>"October 28 & 29, 2010");
	/*'Project Leadership Forum - Early Bird Reg: $325'=>"Project Leadership Forum - Early Bird Reg: $325",'Project Leadership Forum - Early Bird Reg PMI: $295'=>"Project Leadership Forum - Early Bird Reg PMI: $295",'Project Leadership Forum - Registration: $425'=>"Project Leadership Forum - Registration: $425",'Project Leadership Forum - Registration PMI: $395'=>"Project Leadership Forum - Registration PMI: $395"*/
	$progtype_arr = array('CPLP course registration: $1065'=>"CPLP course registration: $1065",'CPLP course early-registration: $1015 *'=>"CPLP course early-registration: $1015 *",'HACCP Manager 2-day: $695'=>"HACCP Manager 2-day: $695",'Implementing SQF – 2-day: $600'=>"Implementing SQF – 2-day: $600",'HACCP Manager 2-day govt, acad, sanit, disct: $395'=>"HACCP Manager 2-day govt, acad, sanit, disct: $395");
	$regtype_arr = array('By Credit'=>"By Credit",'By Phone'=>"By Phone");
?>

<h2>Professional Development Registration</h2>
<hr />Use this form to register for professional development courses such as CPLP on Campus, HACCP Manager Certification, or Implementing SQF Systems Training.<br />
<br />
<form method="post" action="prof-dev-registration-verify.php" name="pdreg" id="pdreg" enctype="application/x-www-form-urlencoded" onsubmit="return validate_form(this);">
<table><tbody>
<tr><td><strong>First Name*:</strong> </td><td>
<input name="ref1type1" type="hidden" id="ref1type1" value="C-FNAME" />
<input name="ref1val1" type="text" id="ref1val1" size="40" value="<?php echo("$sFirstName");?>" />
</td><td>&nbsp;&nbsp;&nbsp;</td><td><strong>Last Name*:</strong> </td><td> 
<input name="ref2type1" type="hidden" id="ref2type1" value="C-LNAME" />
<input name="ref2val1" type="text" id="ref2val1" size="40" value="<?php echo("$sLastName");?>" />
<tr><td>Title: </td><td> 
<input name="ref3type1" type="hidden" id="ref3type1" value="C-TITLE" />
<input name="ref3val1" type="text" id="ref3val1" size="40" value="<?php echo("$sTitle");?>" />
</td><td>&nbsp;&nbsp;&nbsp;</td><td>Employer: </td><td> 
<input name="ref4type1" type="hidden" id="ref4type1" value="employer" />
<input name="ref4val1" type="text" id="ref4val1" size="40" value="<?php echo("$sEmployer");?>" />
</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr><td>Work Phone: </td><td colspan="3"> 
<input name="ref5type1" type="hidden" id="ref5type1" value="workphone" />
<input name="ref5val1" type="text" id="ref5val1" size="40" value="<?php echo("$sWorkPhone");?>" />
</td></tr>
<tr><td>Cell Phone: </td><td colspan="3"> 
<input name="ref6type1" type="hidden" id="ref6type1" value="cellphone" />
<input name="ref6val1" type="text" id="ref6val1" size="40" value="<?php echo("$sCellPhone");?>" />
</td></tr>
<tr><td colspan="4"><strong>*Either a Work or Cell Phone number is required for submission.</strong></td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr><td><strong>Address 1*:</strong> </td><td>
<input name="ref7type1" type="hidden" id="ref7type1" value="C-ADDR" />
<input name="ref7val1" type="text" id="ref7val1" size="40" value="<?php echo("$sAddress1");?>" />
</td><td>&nbsp;&nbsp;&nbsp;</td><td>Address 2: </td><td>
<input name="ref8type1" type="hidden" id="ref8type1" value="address2" />
<input name="ref8val1" type="text" id="ref8val1" size="40" value="<?php echo("$sAddress2");?>" />
</td></tr>
<tr><td><strong>City*: </strong></td><td> 
<input name="ref9type1" type="hidden" id="ref9type1" value="C-CITY" />
<input name="ref9val1" type="text" id="ref9val1" size="40" value="<?php echo("$sCity");?>" />
</td><td>&nbsp;&nbsp;&nbsp;</td><td><strong>State*: </strong></td><td>

<input name="ref13type1" type="hidden" id="ref13type1" value="C-STATE" />
<select name="ref13val1" id="ref13val1">
	<option value="" selected></option>
	<?php showOptionsDrop($states_arr, $selectedState, true); ?>
</select>
</td></tr>

<tr><td><strong>Zip*:</strong> </td><td> 
<input name="ref10type1" type="hidden" id="ref10type1" value="C-ZIP" />
<input name="ref10val1" type="text" id="ref10val1" size="40" value="<?php echo("$sZip");?>" />
</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
<tr><td><strong>Address Type*:</strong> </td><td>
<input name="ref14type1" type="hidden" id="ref14type1" value="addrtype" />
<select name="ref14val1" id="ref14val1">
	<?php showOptionsDrop($addresstype_arr, $selectedAddressType, true); ?>
</select>
</td><td>&nbsp;&nbsp;&nbsp;</td></tr>

<tr><td colspan="4">&nbsp;</td></tr>
<tr><td><strong>E-mail*:</strong> </td><td colspan="3">
<input name="ref11type1" type="hidden" id="ref11type1" value="C-EMAIL" />
<input name="ref11val1" type="text" id="ref11val1" size="40" value="<?php echo("$sEmailAddress");?>" />
</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr><td colspan="5"><strong>How did you learn about this program?*</strong>&nbsp;&nbsp;
<input name="ref15type1" type="hidden" id="ref15type1" value="source" />
<select name="ref15val1" id="ref15val1">
	<option value="" selected>-- Select --</option>
	<?php showOptionsDrop($source_arr, $selectedSource, true); ?>
</select>&nbsp;&nbsp;&nbsp;&nbsp;Other: 
<input name="ref12type1" type="hidden" id="ref12type1" value="sourceother" />
<input name="ref12val1" type="text" id="ref12val1" size="30" value="<?php echo("$sSourceOther");?>" />
</td>
</tr>

<tr><td colspan="4">&nbsp;</td></tr>
<tr><td><strong>Program*:</strong> </td><td>
<input name="ref16type1" type="hidden" id="ref16type1" value="program" />
<select name="ref16val1" id="ref16val1" style="width:200px" >
	<option value="" selected>-- Select --</option>
	<?php showOptionsDrop($program_arr, $selectedProgram, true); ?>
</select>

<tr><td colspan="4">&nbsp;</td></tr><td colspan="8">
<tr><td><strong>Registration Type*:</strong> </td><td>
<input name="ref19type1" type="hidden" id="ref19type1" value="progtype" />
<select name="ref19val1" id="ref19val1" style="width:375px" onchange="setItemCode(this.value);">
<!--<select name="program" id="program" style="width:200px" onchange="setItemCode(this.value);">-->
	<option value="" selected>-- Select --</option>
	<?php showOptionsDrop($progtype_arr, $selectedProgramtype, true); ?>
</select>
</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
<tr><td><strong>Program Date*: </strong></td><td>
<input name="ref17val1" type="hidden" id="ref17val1" value="programdate" />
<input name="ref17val1" type="text" id="ref17val1" style="width:200px">

</td><td>&nbsp;&nbsp;&nbsp;</td></tr>

<tr><td colspan="5">&nbsp;</td></tr>
<tr><td><strong>Payment Method*:</strong> </td><td colspan="6">
<input name="ref18val1" type="hidden" id="ref18val1" value="registrationtype" />
<select name="ref18val1" id="ref18val11">
<option value="" selected>-- Select --</option>
	<?php showOptionsDrop($regtype_arr, $selectedRegistrationType, true); ?>
    </td><td>&nbsp;&nbsp;&nbsp;</td></tr>
</select>

</td>
<div style="visibility:hidden">
<tr><td nowrap="nowrap">
<div id="disc-code1" style="visibility:hidden">
<strong>Discount Code*:</strong>
</div>
</td><td>
<div id="disc-code2" style="visibility:hidden">
<input name="ref24type1" type="hidden" id="ref24type1" value="discountcode" />
<input name="ref24val1" type="text" id="ref24val1" size="15" value="" />
</div>
</td><td>&nbsp;&nbsp;&nbsp;</td></tr>




<div style="visibility:hidden"><input name="dummyfield" type="text" id="dummyfield" /></div>

<input name="itemcode1" type="hidden" id="itemcode1" value="" />
<input name="amount1" type="hidden" id="amount1" value="" />

</tr>
<tr><td colspan="4">&nbsp;</td></tr>
</tbody></table>
<table width="100%"><tbody>
<?php 
if (!$submitted) { ?>
<tr align="center" height="50px"><td bgcolor="#DBCDA8"><br /><font color="#004E35" style="font-weight:bold">If you selected "By Credit Card" as your Registration Type,<br />you will need to complete the payment process by clicking on the "<strong>Make Payment</strong>" button on the confirmation screen.</font><br /><br /><!--<input type="reset" name="reset" id="reset" value="Reset" />&nbsp;&nbsp;--><input type="submit" name="submit" id="submit" value="Submit Registration" /><br />&nbsp;</td></tr>
<? } ?>
</tbody></table>


</form>
<p style="font-size:10px">
Cancellation and Refunds: Harrisburg University reserves the right to cancel or reschedule events and courses at its own discretion.  Should a program be cancelled by the university for any reason, a full refund will be issued.  Cancellations received in writing to  <a href="mailto:[email protected]">[email protected]</a> from individual registrants more than 7 days prior to the start of a program or event are eligible for a 50% refund of fees paid.  No refunds will be issued for cancellations received from individual registrants 6 or less days prior to the start of the event.   

</p>
<?PHP require("../../lib/inc/footer.php"); ?>
</body>
</html>

Answer : Populate text box based on drop down selection?

you have two ref17val1 field (same name same id!!! ), you're setting the first (the hidden one)

you MUST have a UNIQUE id for each field in a page
Random Solutions  
 
programming4us programming4us