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

Targeting an iframe from a JS Submit button

P: n/a

Hi,

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">
</IFRAME>

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

<!--

//Hide from Java Script

function goToPage2()

{

PageIndex2=document.form2.select2.selectedIndex

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

{

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

}

//-->

</script>
--------------------

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.

Thanks
Sheldon
--
sheldongold
------------------------------------------------------------------------
sheldongold's Profile: http://www.highdots.com/forums/m1710
View this thread: http://www.highdots.com/forums/t3193248

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 =
document.form2.select2.options[PageIndex2].value

And that does it.
--
sheldongold
------------------------------------------------------------------------
sheldongold's Profile: http://www.highdots.com/forums/m1710
View this thread: http://www.highdots.com/forums/t3193248

Jan 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.