on load populate combo box from php value

Posted on 2008-11-03
Last Modified: 2012-05-05
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;
Question by:Johnny
    LVL 1

    Accepted 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


    Author Comment

    thank you

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    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…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now