Hello,
I've a problem with php and javascript.
With a tool, I put some data in a database.
The I've a form. In this form I want t o load the saved data from the database.
With javascript I open a popup, from where you can choose the right entry.
If the entry is chosen, the popup will be closed en you return to the form, now filles with your data.
This all works perfect, except at 1 point.
If the text in the database contains a hard return, the javascript doesn't work and errors that the strig isn't closed.
this is my code:
Main:
PHP
<script language="JavaScript">
<!--
function selectItem(){
var selindex=document.myForm.myselect.selectedIndex;
if (selindex!=0) {document.myForm.titel.value=document.myForm.myselect[selindex].value;}
}
var wi=null;
function popUp(){
if (wi) wi.close();
wi=window.open("popup.php","","width=800,height=600,location=yes,scrollbars=no,status=yes");
}
//-->
</script>
Pop-up:
PHP
<script language="JavaScript">
<!--
function selectItem(value){
var selindex
selindex = value;
if (selindex!=0) {
window.close();
window.opener.document.myForm.titel.value=selindex;
}
}
//-->
</script>
<?PHP
if(!empty($_POST["myselect"]))
{
$query = "SELECT Profiel FROM DOORSCHAKELCLUB WHERE Boxnummer = '". $_POST["myselect"] ."'" ;
$profiel = mysql_query($query);
list($_POST["titel"]) = mysql_fetch_row($profiel);
print_r(htmlspecialchars($_POST["titel"]));
?>
<script LANGUAGE="JavaScript">
selectItem('<?=htmlspecialchars($_POST["titel"])?>');
</SCRIPT>
<?PHP
}
644 views