Forum Moderators: coopster
var text = " with...<br><input type='text' name='user_relationwith' value='".$userdata['user_relationwith']."' maxlength='100' class='textbox' style='width:200px;'>" If someone have a sulution to this problem I would appreciate it.
Kind Regards
Starefossen
You are not printing the value, that is the problem you are facing I think
var text = " with...<br><input type='text' name='user_relationwith' value=".<?php echo $userdata['user_relationwith'];?>." maxlength='100' class='textbox' style='width:200px;'>"
It didn't work, I guess the problem is the double qutes inside the javarscript var isn't good. The error is gone but so are the whole rest of the javascript. But using single quotes like this didn't work either:
var text = " with...<br><input type='text' name='user_relationwith' value='.<?php echo $relationwith;?>.' maxlength='100' class='textbox' style='width:200px;'>" Anyway, thanks for giving it a try...
<?php
$var1 = "var text = ' with...<br><input type='text' name='user_relationwith' value='$relationwith' maxlength='100' class='textbox' style='width:200px;'>";
echo $var1;
?>
The whole javascript block is like this:
switch (topic) {
case "In a Relationship":
var heading = "In a Relationship"
var text = " with...<br><input type='text' name='user_relationwith' value=".<?php echo $relationwith;?>." maxlength='100' class='textbox' style='width:200px;'>";
break It switch some thext inside a <span></span> so I can't just use PHP to show it.
As if you are just pre loading all of the contents in the background and switching with javascript then that wont work with php (except to populate your array of contents). As there is no additional request to the server between javascript switches. If you are using ajax then there is the request to the server, so you can use php to help you.
So when you say that the variable is not getting output, do you mean that the string in the variable is not getting output; or are you getting the full <?php blabla;?> output?
This is my jscript.js
function getData(dataSource, spanID)
{
var XMLHttpRequestObject = false;if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
if(XMLHttpRequestObject) {
var obj = document.getElementById(spanID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
function display_help (text) {
document.getElementById("relationship_box").innerHTML = text
}
function show_relationship(topic) {
var today = new Date()
var currYear = today.getYear()
switch (topic) {
case "In a Relationship":
var heading = "In a Relationship"
var text = " with...<br><input type='text' name='user_relationwith' value="<?php echo $relationwith;?>" maxlength='100' class='textbox' style='width:200px;'>";
break
default:
var heading = "Default"
var text = ""
}
display_help(text)
}
It shows the whole php code with variables and <?php?>
One option would be to use .htaccess and add the following lines -
AddType application/x-httpd-php .js
At the top of all .js files you would then need to add -
<?php
header("Content-type: application/x-javascript");
?>
<note>
I use this technique for all my .js and .css so I can compress the files, as quite often these are at least 3 times the size of the html page. The downside is the server takes the hit on performance...hey nothings perfect :) Just I can guarantee that my server has more power than 99.99% of users computers, so I would rather have it do the work.
</note>
The other option is to have the ajax get the variables from a php page i.e. use php $_GET to buid your response text based on what is sent to it by ajax. That I suspect that would be the better answer.
So you can send the ajax to find all the people for your relationship field then use php to search through your database or whatever and return a string to your XMLHttpRequestObject.responseText that you can work through with javascript.