Re: PHP generated javascript problem with dual dropdowns..
| From: | Ryan J Nichols | Date: | Sun, 16 Jul 2000 20:55:52 +0000 |
| Subject: | Re: PHP generated javascript problem with dual dropdowns.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6900@lists.php.net to get a copy of this message | ||
This is a javascript question, please keep these off the php mailing list.
Whether or not the code happened to be generated by php i think is
irrelevant, someone correct me if I'm wrong here.
check http://developer.netscape.com for javascript
resources.
Ryan
----- Original Message -----
From: Chad Day <cday@beachassociates.com>
To: <php-general@lists.php.net>
Sent: Monday, July 17, 2000 3:50 AM
Subject: [PHP] PHP generated javascript problem with dual dropdowns..
> I've sent this code out, which I thought was working, to a few people who
> have asked for it on this list.. maybe they've had some experience with it
> and have fixed it.. but I'm getting really stuck on something, and I don't
> know Javascript well enough to debug this.
>
> The code below is based on code at
>
> http://www.restorationhardware.com/index.htma?SCREEN=store_locator.
>
> The code works fine in NS4 with no Javascript errors, and I've heard it
> works ok in IE4.. but IE5 either gives a variety of error messages.. the
> ones I've gotten have been:
>
> Error: Line 1159 (the last line of code..)
> echo "<SCRIPT
> Language=\"JavaScript\">UpdateCity();</SCRIPT>\n</FORM>";
>
> Object Expected Error
>
> or
>
> Line 13:
>
> in the first function call..
>
> echo "\t\tdocument.choose_store.TEAMNAME.options[City].text =
> '';\n";
>
> "Unspecified Error"..
>
> which doesn't help me very much at all.
>
> The script seems to work ok with the Unspecified Error msg, but the other
> one effectively breaks it. I'm not sure what's causing either of them to
> generate, but the difference between the two seems to be spacing.. a copy
> and paste from one server to another changed the error msg, but a ftp
> transfer kept it the same.
>
> If anyone can help, I would be extremely grateful, as I'm sure a few
others
> out there who mail this list on a near weekly basis asking for code that
> does this.. The code at restoration hardware seems to work, but of course
we
> can only see the generated side of it..
>
> Chad
>
>
> <?
>
> require("/etc/globals.php");
> require("common.php");
>
> // Connect to the Database
> if (!($link=mysql_pconnect($hostname, $username, $password))) {
> DisplayErrMsg(sprintf("error connecting to host %s, by user %s",
> $hostname, $username)) ;
> exit() ;
> }
>
> // Select the Database
> if (!mysql_select_db($databasename, $link)) {
> DisplayErrMsg(sprintf("Error in selecting %s database", $databasename))
;
> DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link),
> mysql_error($link))) ;
> exit() ;
> }
>
> site_header("mbtest");
>
> $fillvendor = mysql_query("select distinct vendor, model from
MainboardDB");
>
> $fillmodel = mysql_query("select distinct vendor, model from
MainboardDB");
>
> $store_state = array();
> $store_id = array();
> $store_city = array();
> while ($row = mysql_fetch_array($fillvendor)) {
> array_push($store_state,$row["vendor"]);
> array_push($store_id,$row["model"]);
> }
>
> while ($row = mysql_fetch_array($fillmodel)) {
> array_push($store_city,$row["model"]);
> }
>
> $numStores = mysql_num_rows($fillmodel);
> $last_value = '';
>
> while ( list( $index, $value) = each ( $store_state)) {
> if ($last_value == $value) {
> continue;
> }
> else {
> $distinct_states[] = $value;
> }
>
> $last_value = $value;
> }
> /* create the javascript function the updates the city
> list */
> echo "<SCRIPT Language=\"JavaScript\">\n";
>
> echo "function UpdateCity()\n";
> echo "{\n";
>
> /* clear the city selector */
> echo "\tvar City =
> document.choose_store.TEAMNAME.options.length;\n";
> echo "\twhile(City > 0)\n";
> echo "\t{\n";
> echo "\t\tCity--;\n";
> echo "\t\tdocument.choose_store.TEAMNAME.options[City].text =
> '';\n";
> echo "\t\tdocument.choose_store.TEAMNAME.options[City].value =
> '';\n";
> echo "\t}\n\n";
> echo "\tdocument.choose_store.TEAMNAME.options[0].selected =
> true;\n\n";
> /* figure out which state is selected*/
> echo "\tvar StateSelected = 0;\n";
> echo
>
"\twhile(document.choose_store.LEAGUENAME.options[StateSelected].selected==f
> alse) StateSelected++;\n\n";
>
> $StoreState = "";
> $CityCount = 0;
> $RowCount = 0;
> while($RowCount < $numStores)
> {
> $store_ID = $store_id[$RowCount];
> $store_State = $store_state[$RowCount];
> $store_City = $store_city[$RowCount];
>
> if($StoreState != $store_State)
> {
> if($StoreState != "")
> {
> echo "\t}\n";
> }
>
> echo
> "\tif(document.choose_store.LEAGUENAME.options[StateSelected].value ==
> '$store_State')\n";
> echo "\t{\n";
>
> echo
> "\t\tdocument.choose_store.TEAMNAME.options[0].value = 0;\n";
> echo
> "\t\tdocument.choose_store.TEAMNAME.options[0].text = 'Choose a
> Model';\n\n";
>
> $StoreState = $store_State;
> $CityCount = 1;
> }
>
> echo
> "\t\tdocument.choose_store.TEAMNAME.options[$CityCount].value =
> '$store_ID';\n";
> echo
> "\t\tdocument.choose_store.TEAMNAME.options[$CityCount].text =
> '$store_City';\n\n";
> $CityCount++;
> $RowCount++;
> }
>
> echo "\t}\n";
> echo "}\n";
> echo "</SCRIPT>\n\n";
>
> echo "<FORM action=\"mbview.php\" METHOD=\"POST\"
target=\"_blank\"
> NAME=\"choose_store\"\n>";
> echo "<p>Vendor Name : ";
> echo "<SELECT NAME=\"LEAGUENAME\"
> onChange=\"UpdateCity();\">\n";
> echo "<OPTION VALUE=\"0\">Choose a Vendor";
> $RowCount = 0;
> while($RowCount < count($distinct_states))
> {
> echo "<OPTION VALUE=\"";
> echo $distinct_states[$RowCount];
> echo "\">";
> echo $distinct_states[$RowCount];
> echo "\n";
> $RowCount++;
> }
> echo "</SELECT>\n";
>
> /* Now we need to know how many cities are listed for
> the state with the most stores */
> /* select count(*) as items from store group by State
> order by items desc */
> $MaxItems = $numStores;
> echo "Model : <SELECT NAME=\"TEAMNAME\">\n";
> $RowCount = 0;
> while($RowCount <= $MaxItems)
> {
> echo "<OPTION VALUE=\"";
> echo $store_city[$RowCount];
> echo "\">";
> echo "Choose a Model\n";
> $RowCount++;
> }
> echo "</SELECT><BR><BR>\n";
> echo "<input type=\"submit\">";
> echo "</CENTER>";
> echo "<SCRIPT
> Language=\"JavaScript\">UpdateCity();</SCRIPT>\n</FORM>";
>
> ?>
> </body>
> </html>
> [admin@cb029 main]$
>
> Chad Day
> Beach Associates
>
> When I speak german... I think german in my head... but like...Do skript
> kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in
> their
> h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>