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

Targeting an iframe from a JS Submit button

P: n/a


I've got a dropdown list of products and I have a button that will add
the product to my cart. However, as with all my 'add to cart' buttons,
when the user clicks it I want to pass the details to my cart via an
iframe so that the user doesn't leave the page they are on. I am
writing in PHP4 and mySQL, and have had to add some javascript for the
onclick event.

The code for the dropdown list is as follows:

PHP code:
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 to add it to the quote...</option><option value="show_cart.php/?new=';
echo $row['productid'];
echo '">';
echo $row['description'];
echo '</option>';
echo '</select> <input type="button" name="B2" id="B2" value="Add to Quote" onclick="goToPage2()" /></form></td>';
echo '<td>';
echo '</td></tr>';
my Iframe code is as follows:

<IFRAME name="iframecart" SRC="show_cart.php" height="1"
width="1" style="display: none">

And the code for the goToPage2 js function is:
<script type="text/javascript">


//Hide from Java Script

function goToPage2()



if (document.form2.select2.options[PageIndex2].value != "none")


location = document.form2.select2.options[PageIndex2].value




I have tried to add target="iframecart" to the <form>, <input>and the
<select> tags but to no avail. I have tried dropping it into the
javascript in a couple of ways, but I have not used JS before and
simply 'borrowed' this bit of script from another webpage...

Any advise greatly received!! I am stuck.

sheldongold's Profile:
View this thread:

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

P: n/a

Just found the solution. The answer's in the JS:

Change the line in the goToPage2 function from:

location = document.form2.select2.options[PageIndex2].value

to this:

parent.iframecart.location =

And that does it.
sheldongold's Profile:
View this thread:

Jan 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.