Forum Moderators: coopster
in the php file used as source for the javascript, ive defined javascript functions which add textfield's dynamically to the form if a user clicks a button. This works fine as said.
However, the menu's wont show.
The php generated javascript functions for the menu's are inside a include, which is included in every file on the site and returns the output (it doesnt echo)
I echo it by calling the it like 'echo $dyn_form_menu', which works fine if I use it as part of html output, but it doesnt output anything in the javascript include
any ideas? must be something simple....
I use a PHP file as a javascript source, in it are 2 things: static javascript functions and dynamically generated ones
I use it like:
<script language="JavaScript" type="text/javascript" src="http://www.site.com/js/form_fields.php"></script>
example static in that file:
<!--
var newProducer = "";
function producerAdd()
{
newProducer+='<input name=\"producer[]\" type=\"text\" class=\"txtfield\"><br/>';
document.getElementById('producer_container').innerHTML = newProducer;
}
-->
a new form field is insert when the user clicks the button, calling the function producerAdd()
the dynamic javascript is a bit more complicated and I think I will need to let you see some code to understand it. It is used on the same pages as the static javascript function, but this is dynamically generated.
I display it in the HTML <head> part of a page simply by using <? echo $movie_country_java;?> now.
What I wanted to do is use it in inside the same javascript source I used like I mentioned before, but this is what I cant get to work.
It also inserts something into the form, this time a html select which is formed by PHP via MySQL queries, when a user clicks the button calling the javascript function countryAdd()
//MOVIE COUNTRIES SELECTOR
$movie_country_java.= "<script language=\"JavaScript\" type=\"text/javascript\">\n";
$movie_country_java.= "<!--\n";
$movie_country_java.= "var newCountry = \"\";\n";
$movie_country_java.= "function countryAdd()\n";
$movie_country_java.= "{\n";
$movie_country_java.= "newCountry+='<select name=\"movie_country[]\" size=\"1\" class=\"menu\">';\n";
$movie_country_java.= "newCountry+='<option value=\"\" selected>select</option>';\n";
{
@mysql_select_db('DB');
$query = 'SELECT movie_country FROM s1 WHERE movie_country IS NOT NULL ORDER BY movie_country';
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$movies_countries = array(); // initialize the countries array
while ($myresult = mysql_fetch_array($result)) // loop through and add each country to the array
{
$movie_countries[]= $myresult;
}
foreach ($movie_countries as $movies_country)
{
$movie_country = ucwords($movies_country[0]);
// build the options...
$movie_country_java.= "newCountry+='<option value=\"$movie_country\"";
$movie_country_java.= ">$movie_country</option>';\n";
}
// close the select tags
$movie_country_java.= "newCountry+='</select><br/>';\n";
$movie_country_java.= "document.getElementById('country_container').innerHTML = newCountry;\n";
$movie_country_java.= "}\n";
$movie_country_java.= "-->\n";
$movie_country_java.= "</script>\n"; }
how can I let this be echoed so that it appears as static? So it should just show in this file:
<script language="JavaScript" type="text/javascript" src="http://www.site.com/js/form_fields.php"></script>