SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : HTML and CSS :

Previous DiscussionNext Discussion
 anybody could give a workaround for this?

hi all,

following code will generate runtime exception, though the code was copied from msdn!

<html>
<head>
<SCRIPT>

<!--
counter = 0;
var text="1";
var value="1";

function addRow(id){
var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR");
var td1 = document.createElement("TD") ;

/* create the input element as a seperate reference */
var input = document.createElement("INPUT");

/* append the attributes to the input element, not td */
input.setAttribute("type","text");
input.setAttribute("name","tbox"+counter);
input.setAttribute("id","tbox"+counter);
td1.appendChild(input);

counter++

var td2 = document.createElement("TD") ;
var input2 = document.createElement("INPUT") ;
input2.setAttribute("type","text");
input2.setAttribute("name","tbox"+counter);
input2.setAttribute("id","tbox"+counter);

counter++

var td3 = document.createElement("TD") ;
var input3 = document.createElement("select") ;

var option1 = document.createElement("option");
input3.options.add(option1);//WILL THROW EXCEPTION HERE!!!!!!
option1.value = "abc";
option1.text="abc";

input3.setAttribute("id","tbox"+counter);
input3.appendChild(option1); input3.appendChild(option2);

counter++

td2.appendChild(input2);
td3.appendChild(input3);
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
tbody.appendChild(row);

input.focus();
input3.onchange=addRow2;
}

function addRow2(){
 addRow('myTable');
}

function add_one_option (text, value, my_listbox) {
 var oOption = document.createElement("OPTION");
 oOption.text=text;
 oOption.value=value;
 my_listbox.options.add(oOption)
 return true;
}


// End -->

</SCRIPT>
</head>
<BODY onLoad="document.getElementById('first').focus();">

<form name=test action=abc.jsp>
<TABLE border=1 cellSpacing=0 id=myTable>
<TBODY>
<TR> <TD> column1</TD> <TD> column2</TD><TD> column3</TD> </TR>

<!-- FOLLOWING onfocus="true" NOT WORKING -->
<TR> <TD><input type=text id="first" name=a  onfocus="true"></TD> <TD><input type=text name=b ></TD><TD><select size=1 name=c onchange="addRow('myTable')">
<option value=a>
<option value=a>A
<option value=a>B
<option value=a>C</TD> </TR>
</TBODY>
</TABLE>

<input TYPE = "submit"  VALUE = "submit">
</form>
</BODY>

 
any guru can solve this? thank you very much in advance!!!

Started By jiangzhan on Jun 1, 2002 at 11:55:21 AM

8 Response(s) | Reply

Earlier Replies | Replies 2 to 8 of 8 | Later Replies
Goto Page: 2 1
jiangzhan on Jun 2, 2002 at 6:44:12 AM (# 2)

well, you are absolutely right!! The problem will occur using ie 5.0, I just test 5.5 and 6.0 they both acting fine!

Thank you for the comments!


simonleung on Jun 2, 2002 at 12:04:40 PM (# 3)
This message has been edited.

where does the problem occur? sorry I have ie6 only.

I think u can simplify your code not using a counter variable, but rows.rowIndex or rows.cells.cellIndex.

n

using Table.insertRow(index) instead of creating a tr element.

It should also be a rows.insertCell(index) method, but nn6 does not implement it yet.

In ie, document.createElement method is a bit diff. from that in nn6. In ie, it can be that: document.createElement("<input type='text' name='tbox'>")

A simple way, but non standard, but works in both ie and nn, is using element.innerHTML.

Good luck


gmenzel on Jun 4, 2002 at 12:39:20 AM (# 4)

IE 5.0 has memory leak bugs that will manifest in javascript routines.  And - although I have not looked into it in detail - your code appears to be recursive (a very surefire way to find memory bugs if they are there).


Silverlight on Jun 4, 2002 at 5:55:36 AM (# 5)
This message has been edited.

One other tip that might help is to add error trapping to your code.  Even if it is something very basic like you see below, it might help to generate an error message when you run it in IE5.  Also, I would recommend  the approach suggested by simonleung to build tables, that might also help to solve your problem.

function doSomething() {

     try {
          alert("I wish that this function worked");
     }

     catch (error) {
          alert("doSomething() in screenfuncs.asp caused the following error: " + error.description) }
     }

}


jiangzhan on Jun 4, 2002 at 10:33:55 AM (# 6)

Thank you very much guys!


tiso on Jul 22, 2002 at 12:27:13 PM (# 7)

input3.appendChild(option1); input3.appendChild(option2);

 

I found it blew up on the use of 'option2'

 

I didn't see it defined anywhere in the document.

 


Nosretep on Jul 22, 2002 at 3:42:04 PM (# 8)

ditto to tiso, the option2 was blowing this puppy out, not sure if it was necessary for anything else, however, get 'er off the page. 


Earlier Replies | Replies 2 to 8 of 8 | Later Replies
Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.