php variable in javascript

kalicki2k

Mitglied
Hallo,
also ich hab da eine kleines Problem. Ich hab da so einen kleinen Editor gebastelt und der funktioniert in Javascript. Und jetzt wollt ich halt noch einen eintrag aus meiner Datenbank da reinladen.
Und ich weiß nicht wie ich bei meinem JS die PHP Variable $content reinladen kann.

Das müßte die Stelle sein die ich updaten muß immer:
Code:
 function processData() {
  if (isIE) 
   var htmlCode = edit.document.body.innerHTML;
  if(isGecko)
   var htmlCode = document.getElementById('edit').contentWindow.document.body.innerHTML;
  document.form_content.content.value = htmlCode;
	if(document.form_content.content.value == '') {
   alert('Da is nix drinnen ... das nicht gut!');
   return false;
  }
 }
und hier mal komplett:
Code:
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><link href="mycms/redaktionsmodus.css" rel="stylesheet" type="text/css">
<style>
.imagebutton {  WIDTH: 20px; HEIGHT: 20px; border:0px; border-color:#FF0000; }
.image	   { WIDTH: 20px; HEIGHT: 20px; }
#edit { border: solid 1px #CDCDCD; }
</style>
<script type="text/javascript"><!--
 var uagent = navigator.userAgent.toLowerCase(),
  isGecko = ( uagent.indexOf('gecko') && navigator.productSub >= 20030210 ),
  isIE = ( uagent.indexOf('msie') != -1 && uagent.indexOf('opera')== -1 && (uagent.indexOf('msie 5.5') == -1 || uagent.indexOf('msie 6.') == -1) );
  
 function InitToolbarButtons() {
  kids = document.getElementsByTagName('div');
  for (var i=0; i < kids.length; i++) {
   if (kids[i].className == 'imagebutton') {
	kids[i].onclick = tbclick;
   }
  }
 }
 function tbmousedown(e) {
  if(isGecko) {
   e.preventDefault();
  }
 }
 function tbmouseout(id) {
  document.images[id].src='mycms/editor/images/buttons/'+ id +'n.gif';
 }
 function tbmouseover(id) {
  document.images[id].src='mycms/editor/images/buttons/'+ id +'a.gif';
 }
 function tbclick() {
  if(this.id == 'createlink') {
   if(isIE) {
	edit.document.execCommand('createlink'); 
	edit.focus();
	   }
   if(isGecko) {  
	var szURL = prompt('Enter a URL:', '');
	document.getElementById('edit').contentWindow.document.execCommand('CreateLink',false,szURL);
   }
	} else if(this.id == 'FontSize') {
   var objelem = document.form_content.sizechange;
   var size = objelem.options[objelem.selectedIndex].firstChild.data;
   if (isIE) {
	edit.document.execCommand('FontSize',false,size);
   }
   if (isGecko) {
	document.getElementById('edit').contentWindow.document.execCommand('FontSize',false,size);
   }
  } else if(this.id == 'FontName') {
   var objelem = document.form_content.fontchange;
   var font = objelem.options[objelem.selectedIndex].firstChild.data;
   if (isIE) {
	edit.document.execCommand('FontName',false,font);
   }
   if (isGecko) {
	document.getElementById('edit').contentWindow.document.execCommand('FontName',false,font);
   }
  } else if(this.id == 'ForeColor') {
   var objelem = document.form_content.colorchange;
   var color = objelem.options[objelem.selectedIndex].firstChild.data;
   if (isIE) {
	edit.document.execCommand('ForeColor',false,color);
   }
   if (isGecko) {
	document.getElementById('edit').contentWindow.document.execCommand('FontName',false,font);
   }
  } else {
   if(isGecko) {
	   document.getElementById('edit').contentWindow.document.execCommand(this.id, false, null);
   }
   if(isIE) {
	edit.document.execCommand(this.id, false, null);
	edit.focus();
   } 
  }
 }
 function Start() {
  if(isGecko) {
   document.getElementById('edit').contentWindow.document.designMode = 'on';
   try {
	document.getElementById('edit').contentWindow.document.execCommand('undo', false, null);
   } catch (e) {
	isGecko = false;
   }
  }
 }
 function processData() {
  if (isIE) 
   var htmlCode = edit.document.body.innerHTML;
  if(isGecko)
   var htmlCode = document.getElementById('edit').contentWindow.document.body.innerHTML;
  document.form_content.content.value = htmlCode;
	if(document.form_content.content.value == '') {
   alert('Da is nix drinnen ... das nicht gut!');
   return false;
  }
 }
//--></script>
</head><body onLoad="Start()">
<form onSubmit="return processData()" name="form_content" action="<?php echo "$form_act"; ?>" method="post">
 <table border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td>
	<div class="imagebutton" id="FontName">
	 <select name="fontchange">
	  <option>Arial</option>
	  <option>Comic Sans MS</option>
	  <option>Times New Roman</option>
	  <option selected="selected">Verdana</option>
	 </select>
	</div>  
   </td>
   <td width="5"><img src="mycms/editor/images/pixeltrans.gif" width="5"></td>
   <td>
	<div class="imagebutton" id="FontSize">
	 <select name="sizechange">
	  <option>1</option>
	  <option selected="selected">2</option>
	  <option>3</option>
	  <option>4</option>
	  <option>5</option>
	  <option>6</option>
	  <option>7</option>
	   </select>
	</div>  
   </td>
   <td width="5"><img src="mycms/editor/images/pixeltrans.gif" width="5"></td>
   <td>
	<div class="imagebutton" id="ForeColor">
	 <select name="colorchange">
	  <option selected="selected">#000000</option>
	  <option>#089EF5</option>
	  <option>#828C96</option>
	   </select>
	</div>  
   </td>
  </tr>
  <tr>
   <td height="5"><img src="mycms/editor/images/pixeltrans.gif" height="5"></td>
  </tr>
 </table>
 <table border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td width="20">
	<div  class="imagebutton" id="bold">
	 <a href="#"><img src="mycms/editor/images/icons/bold.gif" name="bold" title="Bold" alt="Bold" class="image"></a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="5">
   </td>
   <td width="20">
	<div class="imagebutton" id="italic">
	 <a href="#">
	  <img src="mycms/editor/images/icons/italic.gif" name="italic" title="Italic" alt="Italic" class="image">
	 </a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="5">
   </td>
   <td width="20">
	<div class="imagebutton" id="underline">
	 <a href="#">
	  <img src="mycms/editor/images/icons/underline.gif" name="underline" title="Underline" alt="Underline" class="image">
	 </a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="20">
   </td>
   <td width="20">
	<div class="imagebutton" id="justifyleft">
	 <a href="#">
	  <img src="mycms/editor/images/icons/left.gif" name="left" title="Left" alt="Left" class="image">
	 </a>
	</div>
	 </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="5">
   </td>
   <td width="20">
	<div class="imagebutton" id="justifycenter">
	 <a href="#">
	  <img src="mycms/editor/images/icons/center.gif" name="center" title="Center" alt="Center" class="image">
	 </a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="5">
   </td>
   <td width="20">
	<div class="imagebutton" id="justifyright">
	 <a href="#">
	  <img src="mycms/editor/images/icons/right.gif" name="right" title="Right" alt="Right" class="image">
	 </a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="20">
   </td>
   <td width="20">
	<div class="imagebutton" id="insertorderedlist">
	 <a href="#">
	  <img src="mycms/editor/images/icons/orderedlist.gif" name="ol" title="Ordered List" alt="Ordered List" class="image">
	 </a>
	  </div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="5">
   </td>
   <td width="20">
	<div class="imagebutton" id="insertunorderedlist">
	 <a href="#">
	  <img src="mycms/editor/images/icons/unorderedlist.gif" name="ul" title="Unordered List" alt="Unordered List" class="image">
	 </a>
	</div>
   </td>
   <td width="5">
	<img src="mycms/editor/images/pixeltrans.gif" width="20">
   </td>
   <td width="20">
	<div class="imagebutton" id="createlink">
	 <a href="#">
	  <img src="mycms/editor/images/icons/hyperlink.gif" name="web" title="Hyperlink" alt="Hyperlink">
	 </a>
	</div>
   </td>
  </tr>
 </table>
 
 <iframe id="edit" src="mycms/editor/pre_edit.php" width="600" height="275" frameborder="0" marginheight="0" marginwidth="0"></iframe>
  <input type="submit" value="Speichern">
 <textarea name="content" style=" width:1px; height:1; visibility:hidden;"></textarea>

 <script type="text/javascript"><!--
  if(isIE) edit.document.designMode = 'On';
  InitToolbarButtons();
 //--></script>
</form>
</body></html>

Gruß

Kalicki
 
Danke für die schnelle Antwort :)
aber wie bau ich das in mein Javascript ein? Bin nicht fit im Javascript :-(

Code:
 function processData() {
  if (isIE) 
   var htmlCode = edit.document.body.innerHTML;
  if(isGecko)
   var htmlCode = document.getElementById('edit').contentWindow.document.body.innerHTML;
  document.form_content.content.value = htmlCode;
	if(document.form_content.content.value == '') {
   alert('Da is nix drinnen ... das nicht gut!');
   return false;
  }
 }

gruß
kalicki
 
Moin,

Das kommt drauf an, wo du es brauchst....auf den ersten Blick kann ich da nix entdecken, wo du es benötigen könntest:)
 
Also was ich erreichen will. Ist folgendes. Ich will einen Text der aus einer DB kommt in dem Editor anzeigen lassen.



PHP ist kein Problem. Das geht schon. Ich weis nur nicht wie ich es im Editor anzeigen lassen soll.



Gruß

Kalicki
 
Beispiel zu PHP-Variablen in JavaScript:
PHP:
$url="http://www.kde.org";
echo "<button type="button" onclick="top.location.href='.$url.';>Klick mich</button>';

Uebrigens, das Thema gab's vor kurzem erst wenn ich mich recht erinnere. Und wahrscheinlich auch zuvor schon ein paar Tausend mal. Daher haette Dir sicher die Suchfunktion etwas helfen koennen.
 
Zurück