Accessing javascript variable values of a parent page from the lightbox
I have a form inside the main page and I have to populate some of the data present in the form fields into the iframe which is displayed using a lightbox (pretty photo) .I guess I could do it using javascript though I am not exactly sure how .
My current code is :
<a href="index.aspx?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="New form page"><input type="image" style="border-width: 0px;" src="images/form_ordernow_btn.jpg"
tabindex="129" id="Form1_ImageButton1" name="Form1$ImageButton1" onclick="storevariables()"></a>
</div>
<script type="text/javascript">
function storevariables() {
开发者_运维知识库 var firstname = PrimaryForm.elements["FIRST_NAME"].value;
var lastname = PrimaryForm.elements["LAST_NAME"].value;
}
The above code stores the input form data for the fields "FIRST_NAME" and "LAST_NAME" but how do I pass it on the lightbox ?
Any advice would be very helpful
Thanks
If you declare firstname and lastname as global variable i.e. outside the scope of storevariables, then you can access it from your iframe. So in you parent page change the function to:
<script type="text/javascript">
var firstname = "";
var lastname = "";
function storevariables() {
firstname = PrimaryForm.elements["FIRST_NAME"].value;
lastname = PrimaryForm.elements["LAST_NAME"].value;
}
</script>
And inside you iframe you can access them:
<script type="text/javascript">
function someFunc() {
var firsName = parent.firstname;
}
</script>
精彩评论