• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 952
  • Last Modified:

on load populate combo box from php value

here my problem
i have a combobox that populates schools..i want topass the value of this school to a php page that has a combobox init and if the value = a value then it selects that value.


Wittenberg University
University of Louisville
West Liberty State College

user has picked school 2 from previous page. and this value is in $school_pick as "University of Louisville"

how do i get an onload for the combo box to populate the combo box to reflect that please

thank you for any help and code you may propvide
i thought i could do this but its not working
<body bgcolor="#ffffff" link="#5e2f2f" text="#000000" vlink="#666666"  onLoad='document.form.School.selectedIndex = "2";'>

<P><strong> College: &nbsp;
    <SELECT name='School' size='1' onChange='reloadCities(this.selectedIndex);' onclick='enableLoft();'>
      <OPTION value='0'></option>
      <OPTION value='Wittenberg University'>Wittenberg University</option>
      <OPTION value='University of Louisville'>University of Louisville</option>
      <OPTION value='West Liberty State College'>West Liberty State College</option>
&nbsp; &nbsp;&nbsp; &nbsp;
  • 2
1 Solution
Here is one way of doing it:

<?php $selected = 'selected="selected"'; ?>
<SELECT name='School' size='1' onChange='reloadCities(this.selectedIndex);' onclick='enableLoft();'>
  <OPTION value='0'></OPTION>
  <OPTION value='Wittenberg University' <?php if($school_pick == 'Wittenberg University') echo $selected; ?>>Wittenberg University</OPTION>
  <OPTION value='University of Louisville' <?php if($school_pick == 'University of Louisville') echo $selected; ?>>University of Louisville</OPTION>
  <OPTION value='West Liberty State College' <?php if($school_pick == 'West Liberty State College') echo $selected; ?>>West Liberty State College</OPTION>

Open in new window

JohnnyAuthor Commented:
thank you
JohnnyAuthor Commented:
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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