Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write

Status
Not open for further replies.

planeboy747

Technical User
Joined
Jan 11, 2005
Messages
41
Location
US
I can't get this document write code to work? I think it's scripted wrong. I want to document.write the value of the "agency" field in a table cell of the "request" form.

<script>document.writeIn(document.forms.["request"].elements.["agency"].value)</script>

This script is being executed in a table cell after an onClick has occured.

thanks
j

 
NOT AN I!

Code:
document.write[red]l[/red]n(document.forms.["request"].elements.["agency"].value)

that's a lowercase L.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
okay, I had to try something different, that didn't work, but I got real close with my solution, and a little stuck. This script is returning the word "agencyValue" when I meant for it to return the value of the field "agency"?

I'm using script:
---------------------
function doConfirm()
{
var agencyValue = document.getElementById("agency")
return("agencyValue")
}
-------------------------
In my html it reads:
-------------------------
<script type="text/javascript"> document.writeln(doConfirm());</script>
 
what? get rid of those quotes.

Code:
function doConfirm() {
 var agencyValue = document.getElementById("agency")
 return(agencyValue)
}

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
what? no, this is just bad news.

do this:

Code:
function doConfirm() {
 return document.getElementById("agency").value;
}

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
It's still not working...


function doConfirm()
{
return document.getElementById("agency").value;
}
----------------------------------------------------
<input name="agency" type="text" id="agency" tabindex="1" value="" size="25">
----------------------------------------------------
------------This occurs after onClick--------------
---------------------------------------------------
<td width="402" height="20" id="confirmation1">
<script type="text/javascript"> document.writeln(doConfirm());</script>
</td>

Also tried changing to document.write and still didn't work?
 
what's with all these lines? it's not making anything any easier to read. what occurs after "onclick"? What is being clicked? The way you have it there, it "works" fine. You are defaulting the "agency" field to a value of "", then later on in your HTML you are writing that value, which is still "", to the page.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
the onClick in my form open and close <div> tags where I'm hiding other areas of the form. On this particular onclick, the form becomes hidden, and then it's displaying basically a confirmation section with all the form field values (or at least that's what I'm trying to do, but it's not working). I'm not getting any error messages.

Let me ask this...is there a way when that onClick is clicked, to run a function that will populate field id's in confirmation table? That could be a possible solution.

onClick=doConfirm()

And the function:

function doConfirm() {
return document.getElementById("agency").value; = document.getElementyID("confirmation1")

Basically I want to take the value of "agency" in the "confirmation1" field, which I have coded as <script id=confirmation1"></script>

Which, doesnt' work either, I'm grabbing for straws, as you can see.
 
this is an incredible mess. you are making this MUCH more difficult than you have to. Why do you have this in a div's onclick?

document.write will only work properly when you're loading the page. Instead of this, either set the value of a field, or change the innerHTML value.

Or, even better, post your entire code, instead of random snippets, and maybe we'll be able to salvage what you've got.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
The code is long, so let me see if you have any ideas from this, if not, i'll paste all the code

function doConfirm()
{
document.getElementById("confirmation1").innerHTML=document.getElementById("agency").value;
}

in this table cell:


<td width="402" height="20" id="confirmation1">
</td>


and this didn't work either?

j
 
after nine posts, you still claim you're calling this from an onclick event, yet the only code I've seen this called from is inline javascript, which will run on page load.

[tt]What Is It That You Are Clicking To Call This Function?[/tt]

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
you know what, you're right, that will only work on an onload...

okay, here it is, all my code...


<Script Language=JavaScript>
////////////////////////////////
// remove terms and add form //
//////////////////////////////
function authorize()
{
var elem = document.getElementById("second");
elem.style.display = "block";
document.getElementById('accTerms').style.display = 'none';
}
//////////////////////////////////////////////
// create last/first name drop down fields //
////////////////////////////////////////////
function insertRows(isTable){

index = isTable.rows.length;
nextRow = isTable.insertRow(index);
isText1 = nextRow.insertCell(0);
isText2 = nextRow.insertCell(1);
index++;
index = index.toString();
nameStr1 = "Lname"+index;
nameStr2 = "Fname"+index;
txtStr1 = "Last Name "+index+":<br><input name="+nameStr1+" type='text' size='18' maxlength='18'>";
txtStr2 = "First Name "+index+":<br><input name="+nameStr2+" type='text' size='18' maxlength='22'>";
isText1.innerHTML = txtStr1;
isText2.innerHTML = txtStr2;
isText1.width ='25%'
isText2.width = '75%'
}

function adjustRows(isVal,isTable){

currRows = isTable.rows.length;
newRows = isVal;
if (currRows > 0){for (i=0; i<currRows-0; i++){isTable.deleteRow()}}
for (i=0; i<newRows; i++){insertRows(isTable)}
}
/////////////////////////////
// open approval section //
//////////////////////////
function openApprov()
{
var elem = document.getElementById("approvSection");
elem.style.display = "block";
document.getElementById('continue').style.display = 'none';
}
////////////////////////////
// create approval code //
//////////////////////////
var valid = new Array("2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
function getRandom()
{
var num = Math.floor(Math.random() * valid.length);
return valid[num];
}

function randomString()
{
return "4" + getRandom() + getRandom() + getRandom();
}
//////////////////////////////////////////////
// create last/first name drop down fields //
////////////////////////////////////////////
function insertTN(isTable){

index = isTable.rows.length;
nextRow = isTable.insertRow(index);
isText1 = nextRow.insertCell(0);
index++;
index = index.toString();
nameStr1 = "TN1"+index;
txtStr1 = "Passenger "+index+":<br><input name="+nameStr1+" type='text' size='18' maxlength='18'>";
isText1.innerHTML = txtStr1;
isText1.width ='25%'
}

function adjustTN(isVal,isTable){

currRows = isTable.rows.length;
newRows = isVal;
if (currRows > 0){for (i=0; i<currRows-0; i++){isTable.deleteRow()}}
for (i=0; i<newRows; i++){insertTN(isTable)}
}
/////////////////////////////////
// open confirmation section //
//////////////////////////////
function reviewConfirm()
{
var elem = document.getElementById("reviewConfirm");
elem.style.display = "block";
document.getElementById('second').style.display = 'none';
}
//////////////////////////
// confirmation section//
////////////////////////
function doConfirm()
{
document.getElementById("confirmation1").innerHTML=document.getElementById("agency").value;
}
</Script>
<body onload="document.forms['request'].elements['appCode'].value = randomString();">
<span class="cpyBody"><br>
<div id="accTerms">
<table width="608" border="0" cellspacing="0" cellpadding="2" class="cpySmall">
<tr>
<td height="25" valign="top" class="cpyHeader1"><a name="terms" id="terms"></a>Acceptance
of Terms</td>
</tr>
<tr valign="top">
<td height="45" class="cpyBody">By selecting <span class="cpyBold">Agree</span>,
I certify I have read and agree to the terms and conditions<br>
<br>
<span class="cpyHeader2">Terms &amp; Conditions</span> <br>
These are the terms and conditions, blah blah blah. </td>
</tr>
<tr valign="top">
<td height="23" class="cpySmall"> <a href="#terms"><img src="/images/buttons/agree.gif" type="image" alt="Agree" width="61" height="17" border="0" align="right" onClick="authorize()"></a></td>
</tr>
</table>
</div>
<form name="request">
<div id="second" style="display: none;">Complete the following form to create an approval
code for your PNR. This form must be completed in full for each PNR where an exception
is being made. Once you select agree, an approval code will be generated for your
PNR. After you issue your tickets, you will need to provide the ticket numbers to
validate the approval code.<br>
<br>
<table width="608" border="0" cellpadding="5" cellspacing="1" class="tblBorder">
<tr>
<td class="tblWhite">
<table width="608" border="0" cellpadding="0" cellspacing="1">
<tr>
<td valign="top"><table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><span class="cpyBody">*Required</span></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" colspan="3" valign="top" class="cpyHeader1"> Agency
Information</td>
</tr>
<tr>
<td width="32%" class="cpySmall">*Agency name:<br>
<input name="agency" type="text" id="agency" tabindex="1" value="" size="25">
</td>
<td width="20%" class="cpySmall">*ARC number:<br>
<input name="arc" type="text" id="arc" tabindex="2" value="" size="8" maxlength="8">
</td>
<td width="48%" class="cpySmall">E-mail address:<br>
<input name="email-required" type="text" id="email-required" tabindex="3" value="" size="20" maxlength="22">
</td>
</tr>
</table>
<br>
<table width="550" border="0" cellspacing="0" cellpadding="2">
<tr>
<td height="25" colspan="3" valign="top" class="cpyHeader1">Itinerary
Details</td>
</tr>
<tr valign="top">
<td width="70" height="45" class="cpySmall">*Date booked:<br>
<input name="datebooked" type="text" id="datebooked" tabindex="4" value="" size="8" maxlength="8">
</td>
<td width="123" height="45" class="cpySmall">*Record locator:<br>
<input name="recordlocator" type="text" id="recordlocator" tabindex="5" value="" size="18" maxlength="22">
</td>
<td width="345" height="45" class="cpySmall">*Number of passengers: <br>
<select name="numpassengers" tabindex="6" id="numpassengers" onchange="adjustRows(this.value,nameSet);adjustTN(this.value,ticketSet);">
<option value="1" selected>Select one
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
</select>
</td>
</tr>
</table>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td width="14%" height="45" class="cpySmall">*Flight number:<br>
<input name="flightnum" type="text" id="flightnum" tabindex="7" value="" size="5" maxlength="4">
</td>
<td width="18%" height="45"class="cpySmall">*Departure date:<br>
<input name="deptdate" type="text" id="deptdate" tabindex="8" value="" size="8" maxlength="8">
</td>
<td width="24%" height="45" class="cpySmall">*Departure city:<br>
<input name="deptcity" type="text" id="deptcity" tabindex="9" value="" size="12" maxlength="22">
</td>
<td width="44%" height="45" class="cpySmall">*Fare basis:<br>
<input name="farebasis" type="text" id="farebasis" tabindex="10" value="" size="18" maxlength="22">
</td>
</tr>
</table>
<table width="550" border="0" cellpadding="2" cellspacing="0" id="nameSet" class="cpySmall">
<tr>
<td width="25%" height="18" valign="top" class="cpySmall">*Last name
1:<br>
<input name="lname1" type="text" id="lname1" tabindex="11" value="" size="20" maxlength="22">
<br>
</td>
<td width="75%" height="18" valign="top" class="cpySmall">*First name
1:<br>
<input name="fname1" type="text" id="fname1" tabindex="12" value="" size="20" maxlength="22">
</td>
</tr>
</table>
<div id="continue">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"> <a href="#approval"><img src="/images/buttons/continue.gif" alt="Continue" name="Continue" width="83" height="17" border="0" onClick="openApprov()"></a>
</tr>
</table>
</div>
<div id="approvSection" style="display: none;" >
<table width="550" border="0" cellspacing="0" cellpadding="2" class="cpyBody">
<tr>
<td width="542" height="24" valign="top" class="cpyHeader1"><a name="approval"></a>Approval
Code</td>
</tr>
<tr valign="top">
<td height="55">Apply this approval code, <b>
<script type="text/javascript"> document.writeln(randomString());</script>
</b>, to your record and issue your tickets. Once completed, provide
the ticket numbers below to validate your request and submit.
<input name="appCode" type="hidden" id="appCode">
</td>
</tr>
<tr valign="top">
<td height="23"><span class="cpyHeader2">Enter Ticket Numbers</span></td>
</tr>
</table>
<table width="550" border="0" cellspacing="0" cellpadding="0" id="ticketSet">
<tr>
<td><span class="cpySmall">Passenger 1:</span><br>
<input name="tn1" type="text" id="tn1" tabindex="1" value="" size="20" maxlength="22">
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right"><a href="#confirm"><img src="/images/buttons/continue.gif" value="click" alt="Continue" width="83" height="17" border="0" onclick="reviewConfirm()"></a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="reviewConfirm" style="display: none;">
<table width="608" border="0" cellpadding="5" cellspacing="1" class="tblBorder">
<tr>
<td height="434" class="tblWhite">
<table width="608" border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="422" valign="top">
<table width="550" border="0" cellpadding="0" cellspacing="0" class="cpyBody">
<tr>
<td height="26" colspan="2" valign="top"><span class="cpyHeader1"><a name="confirm"></a>Confirm
Your Request</span></td>
</tr>
<tr>
<td colspan="2">Before you submit your request, please confirm your
entries below for accuracy. You can change any information by using
the back button below.</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td height="25" colspan="2" valign="top" class="cpyHeader2">Agency
Information</td>
</tr>
<tr>
<td width="148" height="20">Agency name:</td>
<td width="402" height="20" id="confirmation1">&nbsp;</td>
</tr>
<tr>
<td height="20">ARC/IATA number:</td>
<td height="20" id="confirmation2">&nbsp;</td>
</tr>
<tr>
<td height="20">E-mail address:</td>
<td height="20" id="confirmation3">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td height="25" colspan="2" valign="top" class="cpyHeader2">Itinerary
Details</td>
</tr>
<tr>
<td height="20">Date booked:</td>
<td height="20" id="confirmation4">&nbsp;</td>
</tr>
<tr>
<td height="20">Record locator:</td>
<td height="20" id="confirmation5">&nbsp;</td>
</tr>
<tr>
<td height="20">Number of passengers:</td>
<td height="20" id="confirmation6">&nbsp;</td>
</tr>
<tr>
<td height="20">Flight number:</td>
<td height="20" id="confirmation7">&nbsp;</td>
</tr>
<tr>
<td height="20">Departure date:</td>
<td height="20">&nbsp;</td>
</tr>
<tr>
<td height="20">Departure city:</td>
<td height="20" id="confirmation8">&nbsp;</td>
</tr>
<tr>
<td height="20">Fare basis:</td>
<td height="20" id="confirmation9">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr valign="top" class="cpyBody">
<td width="50%" height="25" class="cpyHeader2">Passenger Name(s)</td>
<td width="50%" height="25" class="cpyHeader2">Ticket Number(s)</td>
</tr>
<tr class="cpyBody">
<td height="20" id="confirmation10">&nbsp;</td>
<td height="20" id="confirmation11">&nbsp;</td>
</tr>
<tr class="cpyBody">
<td height="20" colspan="2" class="cpyHeader2" id="confirmation10">Approval Code</td>
</tr>
<tr class="cpyBody">
<td height="20" colspan="2" id="confirmation29">&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><img name="back" src="/images/buttons/back.gif" width="62" height="17" alt="Back">&nbsp;&nbsp;
<input name="SUBMIT" type="IMAGE" tabindex="21" value="Submit" src="/images/buttons/submit.gif" alt="Submit" width="67" height="17" border="0">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

 
ok, next step is to tell me WHEN you would like the agency field carried over to the cell with an id of "confirmation1".

At what point in this process is that supposed to happen? Currently, with the code you gave me, doconfirm() is never called, only reviewconfirm() is called.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
That section of the form doesn't even show until you click the button in this section of the code:

<td align="right"><a href="#confirm"><img src="/images/buttons/continue.gif" value="click" alt="Continue" width="83" height="17" border="0" onclick="reviewConfirm();doConfirm();"></a></td>

I tried adding it to what I have, but still couldn't get it to work?

thanks
j
 
Changes:

Code:
function reviewConfirm() {
    doConfirm();
    var elem = document.getElementById("reviewConfirm");
    elem.style.display = "block";
    document.getElementById('second').style.display = 'none';
}

function doConfirm() {
    var c1 = document.getElementById('confirmation1');
    c1.innerHTML = document.forms['request'].elements['agency'].value;
}

I assume you'll have to add lines of JavaScript for each element, but hopefully you'll be able to take what I've given you and work that out. Let me know.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
cLFlaVA, do you know how awesome you are?!?!?! It worked, thanks! :)

Jacob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top