Can someone please explain to me how to use header(“Content-Type: text/javascript”)? I want to have code on another page that has <script src=”” /> and I want to be able to access variables defined in the php.
@NogDogJun 15.2006 — #What I was thinking of would go something like this:
On your PHP server, create a file which we'll call combo.php for this example: [code=php] <?php header("Content-Type: text/javascript"); // 1. connect to database // 2. create query (for this example assume it's called $query $options = mysql_query($query); $text = "<select name='combo'>"; while($row = mysql_fetch_array($options)) { $text .= "<option>{$row[0]}</option>"; } $text .= "</select>"; echo "document.write("$text");"; ?> [/code] In your HTML document within the form, you would access it via the script tag: [code=html] <form> <!-- various inputs go here, then for your javascript select element, do this --> <script type="text/javascript" src="http://www.php.server/combo.php"></script> <noscript><p>ERROR: This form requires that Javascript be enabled.</p></noscript> <!-- rest of form follows here --> </form> [/code] This solution has the obvious drawback that JavaScript is required for your form to be complet; thus the better solution is to get everything hosted on a PHP-enabled host.
Brilliant!!!!!!!!!!!!!!! Absolutely brilliant!!!!!!!!!!!!!!! It actually worked!!!!!!!!!!!!!!!!!! It's wonderful!!!!!!!!!!!!!! :rolleyes: I really like it!!!!!!!!!!!!!!!!!! ??????? NogDog, you are a genius!!!!!!!!!!!!!!!!!!!!!! Your answer was phenomenal!!!!!!!!!!! I made a few edits to make it fit my needs. Brilliant!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Excellent, outstanding, marvelous, magnificent, superlative, supernatural, exceptional, terrific, tremendous, super, amazing, fantastic, sensational, out of this world; What is the right adjective?
OMG, NogDog, your answer is brilliant!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You have fixed my two-week long problem!