The following code (HTML) generates a table. Now I'd like to insert a new
row by a javascript.
The following code (javascript) works with the Internet Explorer and also
with Mozilla. However, the inserted button (onClick) in the table does not
work with the Internet Explorer. It only works with Mozilla.
I'm trying the whole Sunday without any success.
Please give me a hint.
Stefan
PS: It seems that also the width-statement (width:75) is not working with
the Internet Explorer.
=============== =============== =============== =============== =
<html>
<script type="text/javascript">
function InsertRow(Where ToInsert) {
var xtable
var xrow
var xcell
var xelement
xtable = document.getEle mentById("MyTab le")
xrow = xtable.insertRo w(WhereToInsert )
xcell = xrow.insertCell (0)
xcell.innerHTML = "Inserted Row"
xcell.setAttrib ute("bgColor", "#008888")
xcell = xrow.insertCell (1)
xcell.innerHTML = ""
xcell.setAttrib ute("bgColor", "#008888")
xelement = document.create Element("input" )
xelement.setAtt ribute("type", "button")
xelement.setAtt ribute("style", "width:75")
xelement.setAtt ribute("value", "Click")
xelement.setAtt ribute("onClick ", "alert('Wow , it works!')")
xcell.appendChi ld(xelement)
}
</script>
<body>
<form name="MyForm">
<table id = "MyTable" width = "400" align = "center">
<tr>
<td width = "50%" style = "background-color:#00ffff">
Text Row 1
</td>
<td width = "50%" style = "background-color:#00ffff">
<input type = "button" style = "width:75" value = "Click"
onClick = "alert('Wow , it works!')">
</td>
</tr>
<tr>
<td width = "50%" style = "background-color:#00ffff">
Text Row 2
</td>
<td width = "50%" style = "background-color:#00ffff">
<input type = "button" style = "width:75" value = "Click"
onClick = "alert('Wow , it works!')">
</td>
</tr>
</table>
<p>
Where to insert the new row:
<input type = "text" name = "InsertRowNumbe r" value = "">
<input type = "button" value = "Add Row" onClick =
"InsertRow(docu ment.MyForm.Ins ertRowNumber.va lue)">
</form>
</body>
</html>
=============== =============== =============== =============== = 6 4015
Stefan Mueller wrote: xelement = document.create Element("input" ) xelement.setAtt ribute("type", "button") xelement.setAtt ribute("style", "width:75") xelement.setAtt ribute("value", "Click") xelement.setAtt ribute("onClick ", "alert('Wow , it works!')")
setAttribute with script in HTML documents gives you all kind of cross
browser incompatibiliti es, it is usually easier and safer to script
element object properties e.g.
xelement.type = 'button';
xelement.style. width = '75px';
xelement.defaul tValue = xelement.value = 'Click';
xelement.onclic k = function (evt) {
alert('Wow, it works cross browser!');
};
--
Martin Honnen http://JavaScript.FAQTs.com/
Hello
You are great!!! I've been testing the whole day and now it works with both
browsers. Many thanks.
Do you perhaps know how to translate the following setAttribute (not working
with the Internet Explorer) to the format xelement.xxx?
xelement.setAtt ribute("class", "style_butt on")
xelement.setAtt ribute("onMouse over", "className =
'style_button_m ouseover'")
xelement.setAtt ribute("onMouse out", "className = 'style_button'" )
Do you also know how to add class, onMouseover and onMouseout to the whole
row:
In HTML I do:
<tr id="MyRow" class = "stil_tabellene intrag"
onMouseover = "className = 'stil_tabellene intrag_mouseove r'"
onMouseout = "className = 'stil_tabellene intrag'">
In JavaScript I guess I have to use xrow.xxx
xtable = document.getEle mentById("MyTab le")
xrow = xtable.insertRo w(WhereToInsert )
Stefan
Hello
You are great!!! I've been testing the whole day and now it works with both
browsers. Many thanks.
Do you perhaps know how to translate the following setAttribute (not working
with the Internet Explorer) to the format xelement.xxx?
xelement.setAtt ribute("class", "style_butt on")
xelement.setAtt ribute("onMouse over", "className =
'style_button_m ouseover'")
xelement.setAtt ribute("onMouse out", "className = 'style_button'" )
xelement.setAtt ribute("tabinde x", "999")
Do you also know how to add class, onMouseover and onMouseout to the whole
row:
In HTML I do:
<tr id="MyRow" class = "stil_tabellene intrag"
onMouseover = "className = 'stil_tabellene intrag_mouseove r'"
onMouseout = "className = 'stil_tabellene intrag'">
In JavaScript I guess I have to use xrow.xxx
xtable = document.getEle mentById("MyTab le")
xrow = xtable.insertRo w(WhereToInsert )
Stefan
Stefan Mueller wrote: xelement.setAtt ribute("class", "style_butt on")
The class attribute is scripted as the property className e.g.
xlement.classNa me = 'style_button';
That is one of the few exceptions and was done because 'class' is a
keyword or reserved word in many programming languages.
xelement.setAtt ribute("onMouse over", "className = 'style_button_m ouseover'")
Within HTML documents you can usually script HTML event handlers as
elementObject.o neventname = expressionYield ingAFunctionObj ect;
e.g.
xelement.onmous eover = function (evt) {
this.className = 'style_button_m ouseover';
}
--
Martin Honnen http://JavaScript.FAQTs.com/
Great! It work's perfekt. Thanks again.
I was quite close. I've tried 'classname' instead of 'className'. It's very
confusing. Sometimes you have to use big letters (like in 'className') and
sometimes only small letters (like in 'onmouseover'). However, I know now
that I always have to try all versions.
What does 'evt' mean in '... = function(evt) {...}? Can I omit it?
I still have one problem with my inserted row. The text style is not
correct.
I HTML I do:
<td width = "50%" align = "center">
<h5 class = "style_table_en try">Text in cell</h5>
</td>
In JavaScript I do:
xcell = xrow.insertCell (2)
xcell.style.wid th = "50%"
xcell.align = "center"
xcell.className = "style_table_en try"
xcell.innerHTML = "New text in cell"
The text 'New text in cell' has not the style 'style_table_en try' because
this style is defined as 'h5.style_table _entry'. How can I add the new text
as '<h5>'?
I tried
xcell.innerHTML = "<h5> New text in cell </h5>"
but it does not work.
Many thanks
Stefan
Stefan Mueller wrote: What does 'evt' mean in '... = function(evt) {...}? Can I omit it?
It is a formal parameter to that function used as an event handler where
certain implementations (Netscape, Mozilla, Opera) pass in the event
object when the event handler is called. If you don't need the event
object in your event handlers you can of course omit the formal
parameter. Having it is closer to what an event handler attribute in
markup translates to in code however.
How can I add the new text as '<h5>'?
You can create any element object with document.create Element e.g.
var h5 = document.create Element('h5');
h5.appendChild( document.create TextNode('Kibol ogy for all'));
xcell.appendChi ld(h5);
--
Martin Honnen http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
Google can't find me a good example of how to use the "if exists"
syntax in MySql. Is it right that to use it this way:
INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
I want to insert into a table but only if the table exists.
How does one, in general, from PHP, test for the existence of a table,
without getting an...
|
by: Thomas Bartkus |
last post by:
The meaning of REPLACE INTO is clear to me.
IF the new record presents new key values, then it is inserted as a new
record.
IF the new record has key values that match a pre-existing record, then
the key violation is ignored and the new record *replaces* the pre-existing
record.
But what about INSERT IGNORE?
Is this a synonym for...
|
by: Karen Middleton |
last post by:
In MS Access I can do in one SQL statement a update if exists else a
insert.
Assuming my source staging table is called - SOURCE and my target
table is called - DEST and both of them have the same structure as
follows
Keycolumns
==========
Material
|
by: serge |
last post by:
I have a scenario where two tables are in a One-to-Many relationship
and I need to move the data from the Many table to the One table so
that it becomes a One-to-One relationship.
I need to salvage the records from the many table and without going
into detail, one of the reasons I can't do the opposite as
there are records in the ONE table...
|
by: Vic Sowers |
last post by:
I'm trying to sort an HTML table (tBody) on one of its columns dynamically.
My approach is to remove all the rows into an array, sort the array, and
insert to rows back into the tBody.
But, there doesn't seem to be any way to insert a pre-existing row into a
table (tBody). I've tried inserting a blank row and replacing it with the
saved...
| |
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then...
|
by: Andrew |
last post by:
Hi, friends,
In ASP, we use
obj = CreateObject("com.dll")
obj.GetHTMLText(inVal, outHTMLTxt1, outHTMLTxt2)
to get different HTML strings based on input values.
Then, we insert them into proper location of HTML something like the
following:
<table>
|
by: Giggle Girl |
last post by:
Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be...
|
by: mmarif4u |
last post by:
Hi everybody,
I already post a thread like this but that was in mysql.
Here i have a problem with all the code,,
<?php // signup.php
include("common.php");
include("db.php");
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |