พอดีอยากจะเขียนให้มันตัดบทความออกเป็น 3 ส่วนเท่ากัน มีท่านได้เขียนได้รบกวนด้วยครับ โดยนำ บทความที่ ตัดได้ไปลงใน textarea1 ,textarea2, textarea3
รบกวนผู้รู้ด้วยครับ..
พอดีลองเขียนแล้วมันไม่ต่อคำให้มันเลือกมาแต่ตัวสุดท้ายของคำ
<html>
<head>
<script type="text/javascript">
function displayResult()
{
var x=document.getElementById("myTextarea").value;
//alert(x);
document.formf.textme1.value=x;
}
function getResult()
{
var sText=document.getElementById("myTextarea").value;
aText = sText.split(" ");
nArray = aText.length;
nKeyword = nArray /3;
// alert(aText);
for (i=0;nArray-1;i )
{
if (i < nKeyword)
{
document.formf.postText1.value=aText[i] " ";
}
else if ( i >= nKeyword && i < nArray - nKeyword)
{
document.formf.postText2.value=aText[i] " ";
}
else
{
document.formf.postText3.value=aText[i] " ";
}
}
}
</script>
</head>
<body>
<textarea id="myTextarea" name="txt1" rows="5" cols="150">
At W3Schools you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP.
Try to avoid using document.write() in real life JavaScript code. The entire HTML page will be overwritten if document.write() is used inside a function, or after the page is loaded. However, document.write() is an easy way to demonstrate JavaScript output in a tutorial.
</textarea>
<form id="formf" name="formf" method="post" action="">
<textarea id="postText1" name="txtpost" rows="3" cols="50"></textarea>
<textarea id="postText2" name="txtpost" rows="3" cols="50"></textarea>
<textarea id="postText3" name="txtpost" rows="3" cols="50"></textarea><br />
<button type="button" onclick="getResult()">Show name of text split</button>
</form>
</body>
</html>