ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: เก๋าลัดคุง ที่ 09 พฤศจิกายน 2008, 11:24:22



หัวข้อ: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: เก๋าลัดคุง ที่ 09 พฤศจิกายน 2008, 11:24:22
ใช้ iframe แทน textarea + PHP หรือ ASP

ผมใช้ iframe แทน textarea + PHP หรือ ASP
อ้างถึง
<iframe id="edit" src="edit.html" width="100%" height="200px"></iframe>

มันติดตรงที่ ค่า Form ของ  iframe จะใช้ PHP
$_POST['edit'] รับค่ายังไงครับผม

ใช้โค้ด Rich และ wysiwg แบบ Mozilla Rich
http://www.mozilla.org/editor/midasdemo/

ขอบพระคุณครับผม


หัวข้อ: Re: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: Tee++; ที่ 09 พฤศจิกายน 2008, 12:28:44
ผมว่า มันน่าจะแบบนรี้มากกว่านะครับ

โค๊ด:
<iframe id="chatEditor" style="width:300px;height:300px;"></iframe>
<script>
chatEditor.document.write("<?php
$explodeResult explode("\r\n"$content);
$total sizeof ($explodeResult);
print("<body bgcolor='#33CC66'><font face='ms sans serif' size='2'>");
for ($count 0$count $total$count ++) {
print($explodeResult[$count]);
}
print("</font></body>");
?>
")

function set_x(){
var x = chatEditor.document.body.innerHTML;
document.theform.hidden_x.value = x;
}

function setMode(bMode){
var sTmp;
isHTMLMode = bMode;
if (isHTMLMode){
sTmp=chatEditor.document.body.innerHTML;chatEditor.document.body.innerText=sTmp;
}
else {
sTmp=chatEditor.document.body.innerText;chatEditor.document.body.innerHTML=sTmp;
}
chatEditor.focus();
}

frames.chatEditor.document.designMode = "on"
</script>


<!-- ค่าส่งไป -->
<input type="hidden" name="hidden_x" value="">


หัวข้อ: Re: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: เก๋าลัดคุง ที่ 10 พฤศจิกายน 2008, 10:05:53
โค๊ด:
<Script  language="javascript">
function check_form(){
var x  ;
x= edit.document.body.innerHTML;
document.form.comment.value = x;
}
</script>

ขอบพระคุณมากๆ ครับ ชิ้ช่องทาง ผมพิ่มค่า ตาม code เวลา post  :'(


หัวข้อ: Re: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: เก๋าลัดคุง ที่ 12 พฤศจิกายน 2008, 13:06:56
ผมติดอีกนิดครับ จะทำแบบ นี้ครับ >>>>  ???
click ที่รูปแล้ว ไปติดที่ form

โค๊ด:
function insertemoticon(emoticon) {
var x  ;
var emoticon ;
var smi = "<img src='/emoticons/small/"+emoticon+"'>";

x= edit.document.body.innerHTML;
document.form.comment.value = x;
x=x+smi;
edit.document.body.innerHTML=x;
}

ผมใช้ code แบบนี้มัน ต่อที่ ข้อความสุดท้าย อยากจะใช้ไว้จุด focus();

เช่น

อ้างถึง
ข้อความ
mouse << อยู่นี้กดรูป  ??? ได้เลย
ข้อความ

ไม่ทราบคำสั่ง JavaScript ครับ ชี้แนะทีครับ ขอบคุณครับ งง คำถามผมไหม


หัวข้อ: Re: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: Tee++; ที่ 13 พฤศจิกายน 2008, 20:59:51
อ้างถึง
ไม่ทราบว่าคุณ "Tee++;" พอจะแก้ปัญหานี้ของผมได้ไหมครับ

ถ้าคุณ "Tee++;" ไม่ทราบวิธีแก้ไขก็ไม่ได้ก็ไม่เป็นไรครับ

ขอบพระคุณครับผม

^
^
^
พูดแบบนี้มันเหมือน หลอกล่อกันนี่  >:(
(ล้อเล่นๆ)


ตัว iframe มันมี id ใช่มั้ยครับ แล้ววิธีที่จะเข้าถึง data ของ iframe ตัวนี้คือเรียก

id.document.body.innerHTML  --> นี่คือข้อมูลที่เราพิมพ์

ดังนั้นการที่เราจะได้ค่ามันเราจะต้องสร้างปุ่ม submit แล้วก็ input hidden สักตัว

พอเรากดที่ ปุ่ม สมมุติเป็น แบบนี้

โค๊ด:
<input type="button" value="Save" onclick="savedata();" />

คือพอเรากดปุ่มเราจะ ไปเรียก function savedata

แล้ว เรามาสร้าง input hidden กัน แบบนี้

โค๊ด:
<input type="hidden" name="editdata" id="mrx" />

สุดท้ายแล้วเรามาเขียน function ตามที่เราเรียกคือ

โค๊ด:
function savedata()
{
  // ตัว id คือ id ของ iframe นะ
  var alldata = id.document.body.innerHTML;
  // จับยัดลง hidden
  document.getElementById('mrx').value = alldata;


  // สุดท้ายแล้วก็สั่งให้ form ที่ครอบมันอยู่ submit เสีย
  //eg
  document.getElementById('frm').submit();
}
-----------------------------------------------
อันนี้ข้อหลัง

โค๊ด:
function setImage(){
  var temp=window.prompt("กรอก url รูปภาพที่ต้องการแทรก","http://");
  if(temp) setsmile("<img src="+temp+"></img>");
}

function setsmile(what){
  frameID.document.body.innerHTML = frameID.document.body.innerHTML+what;
  frames.frameID.focus()
}


หัวข้อ: Re: ใช้ iframe แทน textarea + PHP หรือ ASP
เริ่มหัวข้อโดย: tinnoi ที่ 16 พฤศจิกายน 2008, 16:29:58
โค้ดดีมากเลย มาแอบ copy เก็บไว้ ขอบคุณมากครับ