By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

Multiple Listboxes on page won't work...

P: n/a

Hi,

I'm coding in PHP4 and MYSQL4 and there is a teensy bit of JS in there
as well. I'm haveing trouble with my dropdown lists as when there is
more than one on the page it just says 'error on page' when I click the
button to add to quote. The user is supposed to be able to select
whatever product they want from the dropdown, click a button to add the
selection to the quotation. This adds the product to the quotation page
through a IFRAME so that the user doesn't have to change pages when
they order something and can continue with their quote.

OK. The code for the dropdown list is:
PHP code:
--------------------
if (($lastrow == '3') && ($row['listtype'] != '3'))
{
echo '</select><td>&nbsp;</td><td><input type="button" class="addtocart" name="B2" id="B2" value="Add to Quote" onclick="goToPage2()" />
</form></td></td>';
echo '<td>';
echo '</td></tr>';
}

<<<<<<<SOME OTHER CODE GOES HERE>>>>>>

elseif ($row['listtype'] == '3')
{
if ($lastrow == '2')
{
echo '<tr><td>&nbsp;</td><td>';
echo '<form name="form2" id="form2" action=""><select name="select2" size="1"><option value="none">Please select an option...</option><option value="show_cart.php?new=';
echo $row['productid'];
echo '">';
echo $row['description'];
echo ' - ';
echo $row['price'];
echo '</option>';
$lastrow = $row['listtype'];
}
elseif ($lastrow == '3')
{
echo '<option value="show_cart.php?new=';
echo $row['productid'];
echo '">';
echo $row['description'];
echo ' - ';
echo $row['price'];
echo '</option>';
$lastrow = $row['listtype'];
}
}
--------------------

This is the JScript

Code:
--------------------
<script type="text/javascript">
<!--
//Hide from Java Script
function goToPage2()
{
PageIndex2=document.form2.select2.selectedIndex
if (document.form2.select2.options[PageIndex2].value != "none")
{
parent.iframecart.location = document.form2.select2.options[PageIndex2].value
}
}
//-->
</script>
--------------------

And this is the IFRAME:
Code:
--------------------
<IFRAME name="iframecart" SRC="show_cart.php" height="1" width="1" style="display: none">
</IFRAME>
--------------------

I am guessing that each listbox will have to have a unique id or name
and that the button referring to it will share the unique name. Now I
can do this by using the productid or even another incremental variable
but how do I get the JS to use these variables??

My terrible workaround option is to just use a simple incremental
variable in the PHP and then just make maybe 10 copies of the JS and
tailor them to each possible outcome as it is highly unlikely I'll need
more than 10 different drop downs per page. I know that's an ugly
solution... That's why I need your help, I am really not very good at
this at all...

Thanks in advance!
Sheldon
--
sheldongold
------------------------------------------------------------------------
sheldongold's Profile: http://www.highdots.com/forums/m1710
View this thread: http://www.highdots.com/forums/t3233733

Jan 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

sheldongold wrote:
PHP code: [[snip]

Your PHP code is a server-side script. It would be more helpful if you
posted what the client sees instead, ie, the output/result from
executing php.
<!--
HTML comment delimiters are unnecessary.
//Hide from Java Script
;) You want to hide javascript from javascript? Also Java !=
javascript.
PageIndex2=document.form2.select2.selectedIndex
if (document.form2.select2.options[PageIndex2].value != "none")
{
parent.iframecart.location = document.form2.select2.options[PageIndex2].value
}
}
It's good practice to end your statements with a semicolon. There's a
standard way of accessing forms and its elements:

document.forms["form2"].elements["select2"].selectedIndex.
I am guessing that each listbox will have to have a unique id


Yes, id's are supposed to be unique identifiers.

Make the suggested changes first, and tell us exactly what the error
message is. FireFox is usually the better choice for a more concise
error message compared to Internet Explorer.

Jan 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.