JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 3 votes, 3.67 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 8th, 2001, 11:32 PM
phreq phreq is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: New Zealand
Posts: 167 phreq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 3 sec
Reputation Power: 13
Question Javascript/php select box

I have a page where the options in a select box are generated from the database. I'm trying to grab the selected value using Javascript, and I'm not quite sure why I'm having problems - as I understand it, the php/mySQL should run when the page first loads, and print the html output to the page - so it shouldn't be any different to a normal JS selectbox value.

It could be the JS I'm using, so here's the code for both - any suggestions would be great.

function copyValues()
{
var region = document.form.company_region.value;
var city = document.form.company_city.value;
var suburb = document.form.company_suburb.options[document.form.company_suburb.selectedIndex].value;
var street = document.form.company_street.value;

var address = region + city + suburb + street;

document.form.company_postal.value = address;
}

...

<tr>
<td width="262">Suburb</td>
<td width="194" colspan="2">
<?php
$query = "SELECT Suburb.Name FROM Suburb, City WHERE City.Name='Wellington' AND Suburb.CityID=City.CityID ORDER BY Suburb.Name ASC";
$result = mysql_query ($query,$db_link_id);
$total_num_rec=mysql_num_rows($result);
echo "<select size='1' name=\"company_suburb\">";
if($total_num_rec!=0){
for ($i=0; $i<$total_num_rec; $i++){
$current_row = mysql_fetch_array($result);
$suburb_name=$current_row[Name];
echo "<option>$suburb_name</option>";
}
}else{
$error_msg="No records found";
echo "<option>$error_msg</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
?>

<?php
session_register("company_suburb");
?>
</td>
</tr>

...

Thanks!

Jen

Reply With Quote
  #2  
Old May 8th, 2001, 11:56 PM
R0bb02001 R0bb02001 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Brisbane, Australia
Posts: 32 R0bb02001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 13
What are the problems you are having?

Reply With Quote
  #3  
Old May 9th, 2001, 12:02 AM
phreq phreq is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: New Zealand
Posts: 167 phreq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 3 sec
Reputation Power: 13
sorry - longer explanation

Sorry if that wasn't clear.

Basically, I am taking 4 values from the form after the user has input them:

company_region, which is a simple text box
company_city, which is also a simple text box
company_suburb, which is the dynamic select box
company_street, which is a simple text box.

I'm getting these values and compiling them into one string which is then posted back to the form in the company_postal text box.

At the moment, the script is returning the region, the city and the street value, but is missing the suburb value.

I'm not sure if this is a php error or a JS error. It just doesn't seem to be picking up a value for the company_suburb.

Thanks,

Jen

Reply With Quote
  #4  
Old May 9th, 2001, 04:12 AM
R0bb02001 R0bb02001 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Brisbane, Australia
Posts: 32 R0bb02001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 13
Hehe, I didn't notice the first time, but this is not a PHP nor mySQL nor JavaScript problem.... whats left? HTML.

You didn't specify a value for your options!

Replace
PHP Code:
echo "<option>$suburb_name</option>"


With
PHP Code:
echo "<option value=\"$suburb_name\">$suburb_name"


The </option> tag is not required in HTML programming.

Simple errors are the best errors.

Regards,
Robbo

Reply With Quote
  #5  
Old May 9th, 2001, 02:41 PM
phreq phreq is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: New Zealand
Posts: 167 phreq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 3 sec
Reputation Power: 13
Hooray!

Thanks for that!

Simple errors are indeed the best... can't believe I overlooked that.

Thanks

Jen

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Javascript/php select box

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap