I was just wondering if there was any easy way to convert a document.writeln output to display inside a textarea box in a form. I recently had done an airline reservation assignment (enter 1 for first class, enter 2 for economy class) assignment with all output just written to a blank webpage with window.prompts. Now my teacher wants us to get input (enter 1 or 2) from a textbox and to display all the output inside a textarea box inside a table. Any help? Ill post the code if that helps at all on request. -thanks

This will do it! The value of the input box retrieved, and the output division updated. Creating HTML and inserting it into the document which means that html tags you typed will be appropriately processed. Hope it helps...

<html>
<head>
<title><!--Sample--></title>
<style type="text/css">
<!--
@media screen, handheld {
html, body { margin: 0; padding: 0; }
body { 
     color: #708090;
     font: 70%/1.5em 'Lucida Console', 'courier new', monospace;
     text-align: center;
}
p { 
     float: left;
     clear: both;
     font: normal 12px Verdana, Helvetica, Arial, sans-serif;
     color: #696969;
     margin: 2px 0 10px 10px;
     padding: 0; 
}
b {
     color: green;
}
label { 
     float: left;
     font-size: 14px;
     font-weight: bold;
     text-transform: uppercase;
     margin: 5px 0 5px 10px; 
 }
input {
     width: 200px;
     font-size: 12px;
     font-weight: bold;
     float: left;
     clear: both;
     color: green;
     margin-left: 10px;
     padding: 2px;
     border: 1px solid #eee;
}
#wrapper {
     width: 700px;
     margin-top: 0;
     margin-right: auto;
     margin-bottom: 0;
     margin-left: auto;
     text-align: left;
     padding: 0;
}
#output {
     width: 710px;
     float: left;
     margin: 0;
     padding: 5px;
     width/**/:/**/ 700px;

}
.spacer {
     width: 700px;
     height: 60px;
     float: left;
     margin: 0;
     padding: 0;
}

#generate {
     width: 700px;
     float: left;
     margin: 0 auto;
     padding: 0;
}
#generate form {
     width: 600px;
     height: auto;
     position: relative;
     float: left;
     margin: 0;
}
-->
</style>
<script type="text/javascript">
<!--
document.onkeyup = function(e) {
var e = e ? e : window.event;
var t = e.target ? e.target : e.srcElement;
     if ( (t.name) && (t.name == 'txt') ) {
     var ie = document.all;
     var m = document.getElementById;
     if (ie) {
     ie.output.innerHTML = t.value; }
     else { m('output').innerHTML = t.value;
          } 
     }
}

//-->
</script>
</head>
<body>
<div id="wrapper">
<div id="output"></div>
<div class="spacer"></div>
<div id="generate">
<form action="#" name="frm1" onsubmit="return false;">
<label>Code Input:</label>
<p> Enter an <b>&lt;HTML&gt;</b> code and see the results above. </p> 
<input type="text" name="txt" value="" />
</form>
</div>
</div>
</body>
</html>

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">

<head>
<title>Airline Reservation System</title>

<form id="ourForm" name="myform" >
<table>
<tr><td>Enter 1 for Economy Seat, 2 for First Class</td><td><input type="text" name="box1" size="5"/></td></tr>
<tr><td>Result</td><td><textarea name = "textarea" rows="40" cols="70"/></textarea></td></tr>
<tr><td><input type="button" value="Submit" name="button1"onClick="startArray()"></td>
<td><input type="reset" value="Clear" name="button2"></td></tr></table>
</FORM>
<HEAD>

<script type = "text/javascript">
<!--
var input;
var secondInput;
var element;
var secondElement;
var firstCount = 0;
var economyCount = 0;
var seats = [ ,0,0,0,0,0,0,0,0,0,0]; //allocate 10-element Array

function startArray()
{

formRef = document.getElementById;
input = document.myform.box1.value;
formRef.box1.value="";

for(var i=0; i<11; i++)
{
if (input == 1 || input = 2)
{
element = linearSearch(seats);
if (element == -1 && input == 1)
{
document.myform.textarea.value=("The First Class is already fully booked\n");
secondQuestion(seats);
}
else if (element == -1 && input == 2)
{
document.myform.textarea.value=("The Economy Class is already fully booked\n");
secondQuestion(seats);
}
else
boardingPass(input);
}
//to terminate the program
else
{
document.myform.textarea.value=("Bye-bye!");
System.exit(0);
}}}

function linearSearch(theArray)
{
if (input == 1)
{
for (var n=0; n<6 ; n++)
if (theArray [n] == 0)
return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n++)
if (theArray [n] == 0)
return n;
}
return -1;
}

function boardingPass(theInput)
{
if (input ==1)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the First Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element+"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the Economy Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element +"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}
}
function secondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{

input = 2;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to Economy Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{
input = 1;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to First Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}}
//-->
</script>
</head>
</body>
</html>

well i got this far and it keeps kicking me out of the initial input loop, why?

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">

<head>
<title>Airline Reservation System</title>

<form id="ourForm" name="myform" >
<table>
<tr><td>Enter 1 for Economy Seat, 2 for First Class</td><td><input type="text" name="box1" size="5"/></td></tr>
<tr><td>Result</td><td><textarea name = "textarea" rows="40" cols="70"/></textarea></td></tr>
<tr><td><input type="button" value="Submit" name="button1"onClick="startArray()"></td>
<td><input type="reset" value="Clear" name="button2"></td></tr></table>
</FORM>
<HEAD>

<script type = "text/javascript">
<!--
var input;
var secondInput;
var element;
var secondElement;
var firstCount = 0;
var economyCount = 0;
var seats = [ ,0,0,0,0,0,0,0,0,0,0]; //allocate 10-element Array

function startArray()
{

formRef = document.getElementById;
input = document.myform.box1.value;
formRef.box1.value="";

for(var i=0; i<11; i++)
{
if (input == 1 || input = 2)
{
element = linearSearch(seats);
if (element == -1 && input == 1)
{
document.myform.textarea.value=("The First Class is already fully booked\n");
secondQuestion(seats);
}
else if (element == -1 && input == 2)
{
document.myform.textarea.value=("The Economy Class is already fully booked\n");
secondQuestion(seats);
}
else
boardingPass(input);
}
//to terminate the program
else
{
document.myform.textarea.value=("Bye-bye!");
System.exit(0);
}}}

function linearSearch(theArray)
{
if (input == 1)
{
for (var n=0; n<6 ; n++)
if (theArray [n] == 0)
return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n++)
if (theArray [n] == 0)
return n;
}
return -1;
}

function boardingPass(theInput)
{
if (input ==1)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the First Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element+"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the Economy Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element +"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}
}
function secondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{

input = 2;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to Economy Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{
input = 1;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to First Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}}
//-->
</script>
</head>
</body>
</html>

well i got this far and it keeps kicking me out of the initial input loop, why?

You have assigned the value "2" to variable input...

if (input == 1 || input [B]=[/B] 2)

you should have only checked it

if (input == 1 || input [B]==[/B] 2)
This article has been dead for over six months. Start a new discussion instead.