473,396 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Probem with DOM in Prototype especially in IE

RamananKalirajan
608 512MB
Hi I am working with prototype. I am just a begginer. I tried to create a table dynamically with DOM in prototype. The code is working in Mozilla but not in IE. Any suggestions.


[HTML]<html>
<body>
<input type="button" id="myButton" value="Create Table">
<div id="myDiv">
</div>
</body>
</html>
<script src="prototype.js"></script>
<script type="text/javascript">
$('myButton').observe('click',function(){
var oTable = new Element('table',{style: "border: 2; cellspacing:5; cellpadding:5" });
var tBody = new Element('tbody',{});
var row = new Element('tr',{style: "background-color: lightblue" });
var xx = new Element('input',{name: "user", disabled: false });
var yy = new Element('input',{type: "radio", name: "raduser", disabled: false });
var zz = new Element('input',{type: "checkbox", name: "checkuser", disabled: false });
var zzz = new Element('input',{type:"checkbox", name: "user", value:"Checked"});
var tmp1 = new Element('td',{}).update(xx);
var tmp2 = new Element('td',{}).update(yy);
var tmp3 = new Element('td',{}).update(zz);
var tmp4 = new Element('td',{}).update(zzz);
row.insert(tmp1);
row.insert(tmp2);
row.insert(tmp3);
row.insert(tmp4);
tBody.insert(row);
oTable.insert(tBody);
$('myDiv').appendChild(oTable);
});
</script>[/HTML]

Regards
Ramanan Kalirajan
Aug 20 '08 #1
6 4271
acoder
16,027 Expert Mod 8TB
When you say it doesn't work, what happens? Is there an error?
Aug 20 '08 #2
RamananKalirajan
608 512MB
When you say it doesn't work, what happens? Is there an error?
There was no error. But the thing is I made it working. The thing is i dynamically created a Div in that div I inserted the Div and I appended the Div's innerHTML with the Table. Now its got working.

This is the working code. You can test it with IE. It's working well

[HTML]<html>
<body>
<input type="button" id="myButton" value="Create Input"><br/>
<Table id="myDiv">
<tbody>
<tr>
<th>S.No</th>
<th>Name</th>
<th>Description</th>
<th>Specialisation</th>
</tr>
</tbody>
</Table>
</body>
</html>
<script src="prototype.js"></script>
<script type="text/javascript">
var x=0;
var y;
$('myButton').observe('click',function(){
var row;
if(x%2==0)
row = new Element('tr',{style: "background-color: lightblue" });
else
row = new Element('tr',{style: "background-color: Red"});
var xx = new Element('input',{name: "user", disabled: false });
var yy = new Element('input',{type: "radio", name: "raduser", disabled: false });
var zz = new Element('input',{type: "checkbox", name: "checkuser", disabled: false });
var zzz = new Element('input',{type:"checkbox", name: "user", value:"Checked"});
var tmp1 = new Element('td',{}).update(xx);
var tmp2 = new Element('td',{}).update(yy);
var tmp3 = new Element('td',{}).update(zz);
var tmp4 = new Element('td',{}).update(zzz);
row.insert(tmp1);
row.insert(tmp2);
row.insert(tmp3);
row.insert(tmp4);
x++;
var mDiv = new Element('div',{});
mDiv.insert(row);
$('myDiv').insert(mDiv.innerHTML);
});
</script>[/HTML]

From the line no 39 I had made some changes please have a comparison with previous post code.

Thanks and Regards
Ramanan Kalirajan
Aug 20 '08 #3
acoder
16,027 Expert Mod 8TB
That looks very hacky; you shouldn't need to do that to make it work.

By the way, have you noticed that your JavaScript code is outside the HTML element?
Aug 20 '08 #4
RamananKalirajan
608 512MB
That looks very hacky; you shouldn't need to do that to make it work.

By the way, have you noticed that your JavaScript code is outside the HTML element?
The reason why I have placed the script outside the HTML tag was, before the page gets load some function may not be working. But placing the code outside the HTML tag loads the script first and then loads the HTML element. Thats the simple reason behind it. I tried placing the script tag within the Head tag and run the program it was not working, after that I placed the code outside the HTML then it worked. This is for Prototype Alone not for normal Javascript functions

Regards
Ramanan Kalirajan
Aug 21 '08 #5
acoder
16,027 Expert Mod 8TB
This should not be a problem for Prototype either. Call the JavaScript code onload to avoid referencing elements that haven't yet loaded.
Aug 21 '08 #6
RamananKalirajan
608 512MB
This should not be a problem for Prototype either. Call the JavaScript code onload to avoid referencing elements that haven't yet loaded.
Thanks for your suggestion sir, I will follow it

Regards
Ramanan Kalirajan
Aug 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: petermichaux | last post by:
Hi, I've been reading the recent posts and older archives of comp.lang.javascript and am surprised by the sentiments expressed about the prototype.js library for a few reasons: 1) The library...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
2
by: allen.leis | last post by:
Hey all - I was making a few objects using the prototype.js library and ran into a problem. Specifically I'm trying to create a Squadron class which contains an array of Platform class. All...
3
by: mike_solomon | last post by:
I am trying to use prototype.js to log javascript errors among other things but by including <script type="text/javascript" src="prototype.js"></scriptin my page some of my existing javascript...
2
by: jaysome | last post by:
While looking at the source code for gcc today, I noticed that a prototype for main() was declared. From gcc.c: extern int main (int, const char **); int main (int argc, const char **argv) {...
5
by: ziobudda | last post by:
Hi, I want ask you if, for a web portal/application, is better prototype or Jquery? I don't want to innesc some type of flame, but after the announce that drupal use JQuery and that the new...
6
by: cbare | last post by:
Hello JS Gurus, One thing I haven't figured out about javascript is the treatment of __proto__. Inheritence, whether prototypes or class-based, is just a shorthand form of delegation (leaving...
15
by: MartinRinehart | last post by:
The FAQ shows a mod to String.prototype adding trim, trimRight and trimLeft. Flanagan states, "There is a strong argument against extending built- in types with your own methods; if you do so,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.