Postingan lainnya
membuat form seperti form tanya sekolah koding
Hai, tolong bantuannya saya ingin membuat form koment di web saya. namun dengan tombol tambahan seperti teks tebal, teks miring,dan link. seperti form tanya yang ada di sekolah koding ini.
mohon bantuannya, terimakasih.
1
2 Jawaban:
<b>huruf tebal</b>, maka hasilnya huruf tebal
<i>huruf miring</i>, maka hasilnya seperti ini: huruf miring
<a href="facebook.com">facebook</a>
0
mungkin pake ini bisa
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function formatText(el,tag){
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
if(document.selection){//IE
document.selection.createRange().text=newText;
}
else{//Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
}
}
</script>
</head>
<body>
<form name="myForm">
<textarea name="myTextarea" rows = "12" cols = "50">.</textarea><br>
<input type="button" value="Bold" onclick="formatText (myTextarea,'b');" />
<input type="button" value="Italic" onclick="formatText (myTextarea,'i');" />
<input type="button" value="Underline" onclick="formatText (myTextarea,'u');" />
</form>
</body>
</html>
2