Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  157] [ 1]  / answers: 1 / hits: 27575  / 11 Years ago, fri, june 21, 2013, 12:00:00

I am new to JavaScript.



I have a javascript function which return me country name. Now I have to place this value in the src of iframe. My JavaScript function is as follows:



<script type=text/javascript>
var country = $(#SCountry).val();
function getCountry()
{
var country = $(#SCountry).val();
return country;

}
</script>


I am getting the country value but can't incorporate it in the src of iframe. My iframe src is as follows:



src='https://example.com/?country=javascript:getCountry()'


It's not working.


More From » html

 Answers
3

You can reach the content of your iFrame like this (just be sure to give an ID to the iFrame) This is a pure JS solution:



document.getElementById(iframe_id).contentDocument.getElementById(destination_id).innerHTML = country ;


And your iFrame tag could look like:

<iframe src='https://domain.com/' id=iframe_id>``</iframe>



OR



with php:



JS:



`document.getElementById('iframe_id').src = 'https://domain.com/?country=' + country;`


PHP inside iframe:



$country = $_POST[country];
echo $country; // this echo you can use where you want the result to show up.

[#77501] Thursday, June 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breanab

Total Points: 731
Total Questions: 95
Total Answers: 79

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;