retrive and display

JavaScript and client side scripting.

Moderator: General Moderators

Locked
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

retrive and display

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

An example would help me a lot
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Re: retrive and display

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

kpraman, please try harder to post in the correct forums. I know I'm getting pretty tired of moving your threads.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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? :evil:

If you couldn't find your thread why didnt you do a search on your name? it would have brought it back.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Locked