I've been having all kinds of problems integrating Javascript into my PHP scripts. After some time I've finally managed to get some code that I know works when the textfield values are hard coded. However, I get an error at the bottom of IE whenever I try to get the function to display PHP variables.
I've tried various methods I've found on the web with no luck.
The code causing problems is:
<script language=javascript>
function changeMessage(obj) {
form = document.mainForm;
var bizname = <?php echo($name); ?>;
var address = <?php echo($address); ?>;
if (obj.checked) {
form.name.value = bizname;
form.address.value = address;
form.district.value = "test";
form.town.value = "test";
}
else {
for (var i=0; i<form.elements.length; i++) {
if (form.elements.type == "text") {
form.elements.value = "";
}
}
}
}
</script>
Can anyone tell me the proper method to pass the PHP variables into javascript?