Page 1 of 1

[SOLVED] Text Input Widget to Select Widget Code

Posted: Sat Jun 19, 2004 9:27 pm
by dardsemail
I've updated this posting since I'm not sure its 100% clear what I'm trying to do. I have code that works beautifully in a select menu to allow the user to select the qty of items (from a qty of 1 to 20). From there, the Javascript function 'UpdateQty' is called which calls the UpdateQty function to update the database and so forth.

This select menu is contained within a function called 'ShowCart' which shows the items in a users shopping cart. Anyway, I'm trying to embed the code for the 'select' menu and not having any luck.

Here is what I have thus far in my HTML code - I'd like to embed this in the PHP function 'ShowCart' so that I can have the 'select' menu appear:

Code: Select all

<td width="15%" height="25"><select name="<?php echo $rowї"piecenum"]; ?>" onChange="UpdateQty(this)">
                    <?php
								
									for($i = 1; $i <= 20; $i++)
									{
										echo "<option ";
										if($rowї"qty"] == $i)
										{
											echo " SELECTED ";
										}
										echo ">" . $i . "</option>";
									}
								?>
                  </select>
                </td>
Here's how I have embedded it - but it doesn't seem to show a select menu with the listed # values:

Code: Select all

<?php
		//Show quantity of this item in a text input widget. The user can alter the quantity and update it
		echo "\n<tr>";
		echo "\n\t<td>" .
			"<select name=",$row["piecenum"]," onChange=UpdateQty(this)>";
			for($i = 1; $i <= 20; $i++)
									{
										echo "<option ";
										if($row["qty"] == $i)
										{
											echo " SELECTED ";
										}
										echo ">" . $i . "</option>";
							}
			 "</select></td>";
?>
All I get is a text input box with the current qty (which by default is 1).

Can anyone help me so that I can get this working? It seems to debug fine, but the right result isn't appearing.

Thanks!

Posted: Wed Jun 23, 2004 8:29 pm
by dardsemail
bump - I've bumped this because I changed the content above to see if it made more sense in less tired and less frustrated language :-)

Posted: Wed Jun 23, 2004 9:10 pm
by Illusionist

Code: Select all

echo "\n\t<td>" . "<select name=",$row["piecenum"]," onChange=UpdateQty(this)>";
chagne to:

Code: Select all

echo "\n\t<td>" . "<select name=".$row["piecenum"]." onChange=UpdateQty(this)>";

Posted: Wed Jun 23, 2004 9:11 pm
by feyd
what's UpdateQty (the javascript one) look like?

Posted: Wed Jun 23, 2004 9:45 pm
by dardsemail
Illusionist - I tried that, still getting a text box instead of a select menu. Very odd. If I take the code I listed above and stick it into the HTML it works fine, but doesn't work embedded within another PHP function.


Feyd - Here's the javascript code:

Code: Select all

function UpdateQty(item)
			&#123;
				itemId = item.name;
				newQty = item.options&#1111;item.selectedIndex].text;
				
				document.location.href = 'cart.php?action=update_item&piecenum='+itemId+'&qty='+newQty;
			&#125;

Posted: Wed Jun 23, 2004 9:51 pm
by Illusionist
It's got to be something wrong on your server or something because i just tried your exact code and got a nice little drop-down

Posted: Wed Jun 23, 2004 11:41 pm
by feyd
yeah.. I have no idea how you are getting a textbox... can you post the html code your browser gets? Preferrably most if not all of the page's code.. it may be something else you are doing.. If you have CSS in there from an external file, post that too.

Posted: Thu Jun 24, 2004 8:05 am
by dardsemail
Okay - got it solved. Thanks so much for your help guys!

Turns out I was calling a ShowCart() function that was built within the page - not externally. Of course, I was only updating the external ShowCart() function (what an idiot I am!!!).

Thanks again!!!