[SOLVED] Text Input Widget to Select Widget Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

[SOLVED] Text Input Widget to Select Widget Code

Post 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!
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post 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 :-)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

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

Post by feyd »

what's UpdateQty (the javascript one) look like?
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post 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;
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

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

Post 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.
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post 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!!!
Post Reply