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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write not working correctly in IE

Status
Not open for further replies.

tecasse

Programmer
Feb 1, 2006
3
US
I have the following code in an html page it should basically create a hidden input field on the page that looks something like this:

<input name="snippet1" type="hidden" value="<%=formFields.getValue("fieldName")%>" />

<-------------- HTML ------------->
<script>hiddenField()</script>&lt;%=formFields.getValue(&quot;clientName&quot;)%&gt;
<script>column3()</script>



<-------------- JAVASCRIPT ------------->
function hiddenField(){
document.write('<input name="snippet' + (snippetNum+1) + '" type="hidden" value="')
}

function column3() {
document.write('"/></td><td width="' + column3Width + '" style="vertical-align: bottom;"><input type="button" name="copy' + buttonNum + '" value="Copy" onClick="copy('+ buttonNum + ')" class="button-small" /></td>');
document.write('</tr>');
snippetNum++;
buttonNum++;
}


The function hiddenField() should wrap the beginning of a hidden input field around the "&lt;%=formFields.getValue(&quot;clientName&quot;)%&gt;" and

function column3() has the end of that tag "/>" but for some reason it's displaying the code rather than creating the input field. If I remove the "/>" from the column3() and place on the html page behind the this code like so "&lt;%=formFields.getValue(&quot;clientName&quot;)%&gt;/>" with no changes to the hiddenField function it works fine. This only happens in IE, works fine either way in Firefox. It's as if the IE browers runs the hiddenField function and since that ending tag is not present it interprets it as text and then calls the column3() function and since it already has displayed the "&lt;%=formFields.getValue(&quot;clientName&quot;)%&gt;" it doesn't know what to do with the "/>" so it displays it as well. Does anyone know of a fix for this or have had this problem before?
 
Show your output code, not your ASP script. Also, you're using a lot of variables without showing where you assign the values.

Lee
 
Have you tried specifying a type for the script, and/or putting CDATA statements in? It may well be your poor syntax that is to blame, rather than IE.

While I can't say this for sure - it's a better guess IMHO than saying IE is at fault.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I didn't want to paste all of the code to keep from confusing anyone but here is all of the javascript code

// JavaScript Document

var snippetNum = 0;
var buttonNum = 1;
var tableWidth = 725;
var column1Width = 150;
var column2Width = 400;
var column3Width = 70;
var arrayName = macros;

function tableHeader() {
document.write('<table width="' + tableWidth + '" border="0" cellpadding="0" cellspacing="0" class="snippets">');

}

function column1() {
document.write('<tr >');
document.write('<td width="' + column1Width + '" style="text-transform: capitalize; padding-right: 15px;">' + arrayName[snippetNum] + '</td>');

}

function column2() {
document.write('<td width="' + column2Width + '" style="border-bottom: 1px solid #666666; border-left: 1px solid #666666;">');
}

function hiddenField(){
document.write('<input name="snippet' + (snippetNum+1) + '" type="hidden" value="')
}

function column3() {
document.write('"/></td><td width="' + column3Width + '" style="vertical-align: bottom;"><input type="button" name="copy' + buttonNum + '" value="Copy" onClick="copy('+ buttonNum + ')" class="button-small" /></td>');
document.write('</tr>');
snippetNum++;
buttonNum++;
}

function tableFooter() {
document.write('</table>');
}
 
Why don't you just write the whole thing in ASP rather than mixing client side scripting with server side scripting? That's where you problem most likely is. I've never seen ASP work with &gt; and &lt; as delimiters because those don't get processed until the server-side script processing is over.

Or you could do something like this instead of breaking everything up:
Code:
<script>hiddenField('<%=formFields.getValue("clientName")%>')</script>

function hiddenField(fieldvalue)
{
document.write('<input name="snippet' + (snippetNum+1) + '" type="hidden" value="' + fieldvalue + '"/>') ;
}

function column3()
{
document.write('</td><td width="' + column3Width + '" style="vertical-align: bottom;"><input type="button" name="copy' + buttonNum + '" value="Copy" onClick="copy('+ buttonNum + ')" class="button-small" /></td>');
document.write('</tr>');
snippetNum++;
buttonNum++;
}

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top