Page 1 of 1
retrive and display
Posted: Wed Jan 31, 2007 11:30 pm
by kpraman
Hello,
I have a combo box (drop down). i am retriving various sizes from database and displaying in that.
In another field of that table has its corresponding price for it. if i change the sizes, the corresponding price for each sizes should display, without the form being submitted. (Without using ajax).
Thanx
Posted: Wed Jan 31, 2007 11:37 pm
by superdezign
PHP is server-side, but what you're looking for is a client-side thing.
It's not THAT difficult to do in javascript if you know the variables.
Posted: Wed Jan 31, 2007 11:48 pm
by kpraman
An example would help me a lot
Re: retrive and display
Posted: Wed Jan 31, 2007 11:59 pm
by gavin1996
kpraman wrote:Hello,
I have a combo box (drop down). i am retriving various sizes from database and displaying in that.
In another field of that table has its corresponding price for it. if i change the sizes, the corresponding price for each sizes should display, without the form being submitted. (Without using ajax).
Thanx
you need a Array of Javascript
You should reading all price to the array.
Posted: Thu Feb 01, 2007 12:02 am
by superdezign
Call a function, onChange, to determine which size was chosen, and depending on which size was chosen, alter something whether it be a textbox, or a div containing text/form input
Pseudo-code:
Code: Select all
function showPrice(formHandle, objectHandle){
if(document.forms[formHandle].objectHandle.option[i] == "whatever")
someDiv.innerHTML = "such and such";
}
Of course, for it to be cross browser you may have to mess with some things, but this is nothing you can't learn easily
Posted: Thu Feb 01, 2007 1:05 am
by feyd
kpraman, please try harder to post in the correct forums. I know I'm getting pretty tired of moving your threads.
Posted: Thu Feb 01, 2007 2:11 am
by mikeq
Myself and codergoblin answered your thread yesterday (with code), which is exactly the same question as this one. Why ask the same question twice?
If you couldn't find your thread why didnt you do a search on your name? it would have brought it back.
Posted: Thu Feb 01, 2007 2:14 am
by kpraman
Thanx for your replies.
I retrive the values of sizes and prices and combine them
Code: Select all
$query_size=mysql_query("SELECT * FROM product_details,product_sizes WHERE product_details.productId=$productId AND product_sizes.sizeId=product_details.size");
while($size=mysql_fetch_array($query_size))
{
$sizearr[]=$size['sizeId'];
$price[]=$size['price'];
$dropsize.="<option value=$size[sizeId] onChange=\"call('$size[sizeId]')\">$size[sizeName]</option>";
}
$merge=array_combine($sizearr,$price);
then, in the form
Code: Select all
<td><select name=sizeId onChange=\"call('$size[sizeId]',$merge)\">$dropsize</select></td>
in javascript
Code: Select all
function call(size,merge)
{
alert(merge[size]);// i am not able to get values
}
I am new to js. is it the correct way of passing values?
Posted: Thu Feb 01, 2007 2:19 am
by feyd
For some reason I didn't see the duplicate thread previously. Well, now this is locked .. and you're officially warned about duplicating threads kpraman.