this is the the code, now here is the final result.... I get one combo box
and
one tex box come up, but they are empty...
DAMN!!!
Any ideas on what Im doing wrong please..
Thanks Again
<?php require_once('..\library_database\Connections\onli nequote.php'); ?>
<?
function select_cases_price ()
{
$qy = "SELECT SellingPrice, Description FROM cases";
$rs = mysql_query ($qy) or die (mysql_error ());
while (mysql_fetch_array ($rs))
{ $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n";
$prices[] = $r{1};
}
return array ($select, $prices);
}
?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?> And a bit of JS:
<script>
function showPrice() {
array prices (<? echo $prices ?>);
var i = document.form.item.selectedIndex; document.form.SellingPrice =
prices[i]; </script>
<select name="Description" onUpdate="showPrice()"> <? echo $select; ?>
</select> <input type="text" name="SellingPrice" value=""> 18 7509
Phill Long wrote: <? function select_cases_price () {
// I like to initialize variables
$prices = array();
$select = '';
$qy = "SELECT SellingPrice, Description FROM cases"; $rs = mysql_query ($qy) or die (mysql_error ()); while (mysql_fetch_array ($rs))
while ($r = mysql_fetch_array ($rs))
// ____^^^^^________________________
{ $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n"; $prices[] = $r{1};
// ?? __________^_^_ is this ok?
// shouldn't it be
$prices[] = $r[1];
// ... I didn't test it with curly braces
} return array ($select, $prices);
// $prices is an array
} ?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?> And a bit of JS:
// $prices is an array!
<script> function showPrice() { array prices (<? echo $prices ?>);
// same as
array prices (Array);
// probably wrong I think :-)
(snip)
Happy bug hunting :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Pedro Graca wrote: <script> function showPrice() { array prices (<? echo $prices ?>);
// same as array prices (Array); // probably wrong I think :-)
Maybe imploding the array is enough?
array prices (<?php echo implode(', ', $prices); ?>);
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Did the things requested, but still not working, any ideas??
I get the combo box to read all the case details, but I just cant get the
thing to put a price in the little text box.. thats all I ask, please help
me..
here is a link to the site..
: http://djsleepy.servebeer.com/all%5F...jsleepy/_test/
<?php require_once('..\library_database\Connections\onli nequote.php'); ?>
<?
function select_cases_price ()
{
$qy = "SELECT Description, SellingPrice FROM onlinequote.cases";
$rs = mysql_query ($qy) or die (mysql_error ());
while ($r=mysql_fetch_array ($rs))
{ $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n";
$prices[] = $r{1};
}
return array ($select, $prices);
}
?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script>
function showPrice()
{
array prices (<? echo $prices ?>);
var i = document.form.item.selectedIndex; document.form.SellingPrice =
prices[i];
</script>
<select name="Description" onUpdate="showPrice()"> <? echo $select; ?>
</select> <input type="text" name="SellingPrice" value="">
Phill Long wrote: Did the things requested, but still not working, any ideas??
(snip) And a bit of JS:
<script> function showPrice() { array prices (<? echo $prices ?>);
Still printing "Array" inside the JS? :)
See the source of your page and you'll see
<script>
function showPrice()
{
array prices (Array);
which, obviously (though I don't know JavaScript), is wrong.
Try the implode(', ', $prices) I told you on my last post. I expect the
JS to become
<script>
function showPrice()
{
array prices (4.5, 126.33, 88, 0.3);
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Phill Long wrote: Did the things requested, but still not working, any ideas?? I get the combo box to read all the case details, but I just cant get the thing to put a price in the little text box.. thats all I ask, please help me.. here is a link to the site.. :http://djsleepy.servebeer.com/all%5F...jsleepy/_test/
<?php require_once('..\library_database\Connections\onli nequote.php'); ?>
<? function select_cases_price () { $qy = "SELECT Description, SellingPrice FROM onlinequote.cases"; $rs = mysql_query ($qy) or die (mysql_error ()); while ($r=mysql_fetch_array ($rs)) { $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n"; $prices[] = $r{1}; } return array ($select, $prices); } ?>
There were a few errors in the JS. Use the implode() thing Pedro mentioned.
The code below is tested on IE5/Win98:
<script>
function showPrice()
{
var prices = new Array(100, 110, 120, 130, 140,150);
var i = document.forms[0].Description.selectedIndex;
document.forms[0].SellingPrice.value = prices[i];
}
</script>
<form>
<select name="Description" onChange="showPrice()"> <option value='Thermaltake
Lanfire Black ATX Case With Side Window No PSU'>Thermaltake Lanfire Black ATX
Case With Side Window No PSU</option>
<option value='Thermaltake Lanfire Silver ATX Case With Side Window No
PSU'>Thermaltake Lanfire Silver ATX Case With Side Window No PSU</option>
<option value='Thermaltake Screwless Skull Atx Case in Black No PSU'>Thermaltake
Screwless Skull Atx Case in Black No PSU</option>
<option value='Thermaltake Xaser III Supertower Black ATX Case With Window No
PSU'>Thermaltake Xaser III Supertower Black ATX Case With Window No PSU</option>
<option value='ATX Midi Tower Case 350w PSU in Black'>ATX Midi Tower Case 350w
PSU in Black</option>
<option value='ATX Case In Silver With Front USB/Audio/1394'>ATX Case In Silver
With Front USB/Audio/1394</option>
</select>
<input type="text" name="SellingPrice" value="">
</form>
Notes:
Use implode or join to print out the array so it looks like the JS code above.
I changed the onUpdate() handler to onChange.
"item" in the original should be "Description".
You need <FORM> tags if you're going to reference using document.forms...etc.
If this isn't the first form, you'll have to change forms[0] to whatever.
You might want to put onLoad="showPrice()" in the body tag to set the intial
price
Regards,
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
Yet again I have ammended the code to suit what has been suggested, but
still cant get that ole text box to display the price.. HELP ME PLEASE!
<?php require_once('..\library_database\Connections\onli nequote.php'); ?>
<body onLoad="showPrice()">
</body>
<?
function select_cases_price ()
{
$qy = "SELECT Description, SellingPrice FROM onlinequote.cases";
$rs = mysql_query ($qy) or die (mysql_error ());
while ($r=mysql_fetch_array ($rs))
{ $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n";
$prices[] = $r[1];
}
return array ($select, $prices);
}
?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script>
function showPrice()
{
var prices = new Array(100, 110, 120, 130, 140,150);
var i = document.forms[0].Description.selectedIndex;
document.forms[0].SellingPrice.value = prices[i];
}
</script>
<select name="Description" onChange="showPrice()"> <? echo $select; ?>
</select> <input type="text" name="SellingPrice" value="">
"Phill Long" <dj******@djsleepy.co.uk> wrote in message news:<c0**********@hercules.btinternet.com>... Yet again I have ammended the code to suit what has been suggested, but still cant get that ole text box to display the price.. HELP ME PLEASE!
<?php require_once('..\library_database\Connections\onli nequote.php'); ?> <body onLoad="showPrice()"> </body> <? function select_cases_price () { $qy = "SELECT Description, SellingPrice FROM onlinequote.cases"; $rs = mysql_query ($qy) or die (mysql_error ()); while ($r=mysql_fetch_array ($rs)) { $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n"; $prices[] = $r[1]; } return array ($select, $prices); } ?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script> function showPrice() { var prices = new Array(100, 110, 120, 130, 140,150); var i = document.forms[0].Description.selectedIndex; document.forms[0].SellingPrice.value = prices[i]; } </script>
<select name="Description" onChange="showPrice()"> <? echo $select; ?> </select> <input type="text" name="SellingPrice" value="">
I checked your previous mail and the URL you have posted.
You are not using any *form* tags to enclose your *select-box* and *text-box*
Use form tags, your page will work fine.
Hope it will help.
--
Cheers,
Rahul Anand
Phill Long wrote: Yet again I have ammended the code to suit what has been suggested, but still cant get that ole text box to display the price.. HELP ME PLEASE!
<?php require_once('..\library_database\Connections\onli nequote.php'); ?> <body onLoad="showPrice()"> </body> <? function select_cases_price () { $qy = "SELECT Description, SellingPrice FROM onlinequote.cases"; $rs = mysql_query ($qy) or die (mysql_error ()); while ($r=mysql_fetch_array ($rs)) { $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n"; $prices[] = $r[1]; } return array ($select, $prices); } ?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script> function showPrice() { var prices = new Array(100, 110, 120, 130, 140,150); var i = document.forms[0].Description.selectedIndex; document.forms[0].SellingPrice.value = prices[i]; } </script>
<select name="Description" onChange="showPrice()"> <? echo $select; ?> </select> <input type="text" name="SellingPrice" value="">
Yes, what Rahul said. And when you're working with Javascript, always put it in
a proper HTML document. That means, put in <HTML> tags, put your select and
option tags within <FORM> tags, and don't close your <BODY> before you start
your form. If you insist on taking these kind of shortcuts you're only going to
end up frustrating yourself.
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
Ok I did all that re-coding and the page works fine apart from I want the
array of prices to come from the mysql table. I dont want to have to enter
them. as I am going to use this for quite a few products.. can this be
done..
Thanks in Advance Guys, u've been brilliant so far!
"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:40***************@glassgiant.com... Phill Long wrote: Yet again I have ammended the code to suit what has been suggested, but still cant get that ole text box to display the price.. HELP ME PLEASE!
<?php require_once('..\library_database\Connections\onli nequote.php');
?> <body onLoad="showPrice()"> </body> <? function select_cases_price () { $qy = "SELECT Description, SellingPrice FROM onlinequote.cases"; $rs = mysql_query ($qy) or die (mysql_error ()); while ($r=mysql_fetch_array ($rs)) { $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n"; $prices[] = $r[1]; } return array ($select, $prices); } ?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script> function showPrice() { var prices = new Array(100, 110, 120, 130, 140,150); var i = document.forms[0].Description.selectedIndex; document.forms[0].SellingPrice.value = prices[i]; } </script>
<select name="Description" onChange="showPrice()"> <? echo $select; ?> </select> <input type="text" name="SellingPrice" value=""> Yes, what Rahul said. And when you're working with Javascript, always put
it in a proper HTML document. That means, put in <HTML> tags, put your select
and option tags within <FORM> tags, and don't close your <BODY> before you
start your form. If you insist on taking these kind of shortcuts you're only
going to end up frustrating yourself. -- Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
<?php require_once('..\library_database\Connections\onli nequote.php'); ?>
<html>
<body onLoad="showPrice()">
<?
function select_cases_price ()
{
$qy = "SELECT Description, SellingPrice FROM onlinequote.cases";
$rs = mysql_query ($qy) or die (mysql_error ());
while ($r=mysql_fetch_array ($rs))
{ $select .= "<option value='{$r[0]}'>{$r[0]}</option>\n";
$prices[] = $r[1];
}
return array ($select, $prices);
}
?>
On your web page, call the function.
<? list ($select, $prices) = select_cases_price (); ?>
And a bit of JS:
<script>
function showPrice()
{
var prices = new Array(120,130,110,120,120,110);
var i = document.forms[0].Description.selectedIndex;
document.forms[0].SellingPrice.value = prices[i];
}
</script>
<form>
<select name="Description" onChange="showPrice()"><? echo $select;
?></select>
<input type="text" name="SellingPrice" value="">
</form>
</body>
</html>
Phill Long wrote: <script> function showPrice() { var prices = new Array(120,130,110,120,120,110);
You once almost had this right!
The prices come from the DB, they are not constants.
You had something like
var prices = new Array(<?php echo $prices; ?>);
and, as $prices is an array that didn't work.
You have to transform the array of prices into a string of values.
[code working="false"]
<?php echo $prices; ?>
[/code]
outputs "Array"
[code working="false" better="true"]
<?php
foreach ($prices as $value) {
echo "$value,";
}
?>
[/code]
outputs "120,130,110,120,120,110," with the final extra comma
but
[code working="true"]
<?php echo implode(",", $prices); ?>
[/code]
outputs "120,130,110,120,120,110" right the way you want :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
nearly right.. Sorry
this displays the price as 16.2, if the price is 16.20... But is there a way
to display the whole value (e.g 16.20) ??????
"Pedro Graca" <he****@hotpop.com> wrote in message
news:c0*************@ID-203069.news.uni-berlin.de... Phill Long wrote: <script> function showPrice() { var prices = new Array(120,130,110,120,120,110);
You once almost had this right! The prices come from the DB, they are not constants.
You had something like var prices = new Array(<?php echo $prices; ?>);
and, as $prices is an array that didn't work.
You have to transform the array of prices into a string of values.
[code working="false"] <?php echo $prices; ?> [/code] outputs "Array"
[code working="false" better="true"] <?php foreach ($prices as $value) { echo "$value,"; } ?> [/code] outputs "120,130,110,120,120,110," with the final extra comma
but [code working="true"] <?php echo implode(",", $prices); ?> [/code] outputs "120,130,110,120,120,110" right the way you want :) -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =--
Phill Long wrote: nearly right.. Sorry
this displays the price as 16.2, if the price is 16.20... But is there a way to display the whole value (e.g 16.20) ??????
You're printing the price in JavaScript. I don't know that.
If it were PHP
<?php echo number_format(16.2, 2); ?>
outputs 16.20.
You might try to replace the implode() thing with another method that
writes the JavaScript array as an array of strings
formatted the way you want -- left as an exercise
or
.... do it in JavaScript
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
but
[code working="true"]
<?php echo implode(",", $prices); ?>
[/code]
outputs "120,130,110,120,120,110" right the way you want :)
I mean the price from the mysql database is 16.20, and the webpage displays
16.2 from this code... So how do I alter this code to make it display 16.20
on the page
Phill Long wrote: but [code working="true"] <?php echo implode(",", $prices); ?> [/code] outputs "120,130,110,120,120,110" right the way you want :)
I mean the price from the mysql database is 16.20, and the webpage displays 16.2 from this code... So how do I alter this code to make it display 16.20 on the page
I think your best option is using JavaScript ... but I don't know how to
do it in JavaScript.
Leave the PHP as is and format the string with JS functions.
Probably comp.lang.javascript is a better place to ask your question.
....................................
If you really want to do it in PHP, then you have to change that code
above so that it outputs
'120.00','130.00','110.00','120.00','120.00','110. 00'
which is left as an exercise :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Phill Long wrote: but [code working="true"] <?php echo implode(",", $prices); ?> [/code] outputs "120,130,110,120,120,110" right the way you want :)
I mean the price from the mysql database is 16.20, and the webpage displays 16.2 from this code... So how do I alter this code to make it display 16.20 on the page
Pedro has already given you the solution. You want the resulting HTML code to
look like this:
var prices = new Array("120.00","130.00","110.00","120.00","120.00" ,"110.00");
He's even suggested the function, number_format, that will format the prices
with the .00 (or whatever) on the end. It's now a simple matter to print the
array out to make it look like the above. Use basic php like foreach and
modifying the code.
Hint: when people in this group use phrases like "left as an exercise" it's
usually because the code is too long or tiresome to write out or they feel that
they're being called on to do something so simple that they've crossed the line
from providing tips and guidance into doing someone else's work for them.
Hint2: the code to do this is not tiresome or long. :)
Regards,
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
please gimme another clue, Im really new to all this and just wanna learn..
I am also still waiting for a slow delivery of my php/mysql book from
amazon...
PRETTY PLEASE WITH SUGAR ON TOP!
Phill Long wrote: please gimme another clue, Im really new to all this and just wanna learn..
I am also still waiting for a slow delivery of my php/mysql book from amazon...
PRETTY PLEASE WITH SUGAR ON TOP!
Why don't you read php.net for foreach, join and number_format and try it. You
really do learn a lot more when you try things yourself. If you run into
trouble, post what you've done. Actually, if you don't run into trouble, let us
know that too.
Regards,
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vic Spainhower |
last post by:
Hello,
I am new to php and mySQL so this is probably something very basic that I'm
missing. Basically, on the page I have 2 combo boxes but 1 of them is not
getting the value passed when the...
|
by: meganrobertson22 |
last post by:
Hi Everyone-
I have a question about how to add and then use the "All" selection in
a combo box. I am trying to figure out how to:
(1) add "All" as a selection to a combo box and then
(2)...
|
by: Mark L. Breen |
last post by:
Hello Guys and Galls,
I use combos on my forms.
The code to initialise the combos is as follows
Dim dsPIDTypes As DataSet
dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object...
|
by: Edwinah63 |
last post by:
Hi everyone,
Please let there be someone out there who can help.
I have two BOUND combo boxes on a continuous form, the second being
dependent on the first. I have no problem getting the...
|
by: LiquidG |
last post by:
Hi,
I have been working on this problem for about 5 days now, and I cant find anything on the web to help me.
Ill tell you the end result, first... My combo box is listing the same data over...
|
by: alandiit |
last post by:
Hi every body
I would like connect three combo box (CascadingDropDown with a Database) MYSQL by asp classic or Java Script .
But I have a problem with this example , when I will change City ,...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |