Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 21st, 2006, 09:57 PM
madhombre madhombre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: WI
Posts: 247 madhombre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
DOM/Adding elements and events

Been a while, have this issue with DOm and not sure if it is possible or not

This is where the basis cames from

http://javascriptkit.com/javatutors/dom2.shtml

and here is my code.

Two issues -

1) the set attrribute for name does not work, why not I do not know but when I show the innerHTML it is not even listed.
2) the on change even is showing when I list the innerHTML but it does not trigger, why not? any way to make it work, if not the concept is totally useless to me. (main point)

(I know php can easily write out the form but I wanted something different. It all works except for this stuff. Also this is test code so there is only a litle data in here)

Thanks in advance.

<html>
<head>
<script language="javascript">

var myitems = new Array(100);

myitems[0] = new Array(100);
myitems[0][0] = new Array(2);
myitems[0][0][0] = "Main Numbers";
myitems[0][0][1] = "none";
myitems[0][1] = new Array(2);
myitems[0][1][0] = "something";
myitems[0][1][1] = "wow";

myitems[1] = new Array(100);
myitems[1][0] = new Array(2);
myitems[1][0][0] = "Other Numbers";
myitems[1][0][1] = "none";

myitems[2] = new Array(100);
myitems[2][0] = new Array(2);
myitems[2][0][0] = "Links";
myitems[2][0][1] = "none";

myitems[3] = new Array(100);
myitems[3][0] = new Array(2);
myitems[3][0][0] = "Phone Numbers";
myitems[3][0][1] = "none";

function loaddata()
{
a = 0;
while (myitems[a] != undefined)
{
myselect = document.createElement('select');
myselect.setAttribute('id',myitems[a][0][0]);
myselect.setAttribute('name',myitems[a][0][0]);
myselect.setAttribute('size', 1);
myselect.setAttribute('onChange','alert('test');') ;

b = 0;

while (myitems[a][b] != undefined)
{
myselect.options[myselect.length] = new Option(myitems[a][b][0], myitems[a][b][1]);
b++;
}

document.getElementById('databuddy').appendChild(m yselect);
a++;
}


alert(document.body.innerHTML)
}

function go(mystr)
{
alert(mystr);
}

</script>
</head>

<body onload="loaddata();">
<form name="databuddy" id="databuddy">


</form>
</body>

</html>

Reply With Quote
  #2  
Old February 22nd, 2006, 11:30 PM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: DOM/Adding elements and events

This appears to be another unfortunate IE issue. Your code functions correctly as-is under FF. It seems that if you use
Code:
myselect.setAttribute('NAME',myitems[a][0][0]);

it will handle the name issue. For the onchange I looked around a bit and found this:

http://www.codecomments.com/archive298-2004-7-244684.html

which leads to:

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/attachevent.asp

I can't offer a fix, but hopefully this gets you headed in the right direction...

Reply With Quote
  #3  
Old February 23rd, 2006, 12:35 AM
madhombre madhombre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: WI
Posts: 247 madhombre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: DOM/Adding elements and events

well the name bit works, uppercase geez!

anyways on to the new stuff

myselect = document.createElement('select');
myselect.setAttribute('id',myitems[a][0][0]);
myselect.setAttribute('NAME',myitems[a][0][0]);
myselect.setAttribute('size', 1);
myselect.attachEvent('onChange','go');

my middle part now reads and I can't make it work.
I get type mismatch errors. I also tried addEventListener that failed.

The go function exists, I will have to look again tomorrow. I am out of time now.

Thanks for the help.

Reply With Quote
  #4  
Old February 23rd, 2006, 10:03 PM
madhombre madhombre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: WI
Posts: 247 madhombre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: DOM/Adding elements and events

finally got it solved, I include just the javascript part here

some noticable points -
1) as noted the name attribute has tio be uppercase
2) onchange has to be LOWERcase not onChange
3) the function name does not have quotes around it in the attachEvent
4) I also inlude how to figure out what item called this because uou can't pass a parameter to the function in the attachEvent call.

Thanks to all who helped.

function loaddata(parentobj)
{
a = 0;
while (myitems[a] != undefined)
{
myselect = document.createElement('select');
myselect.setAttribute('id',myitems[a][0][0]);
myselect.setAttribute('NAME',myitems[a][0][0]);
myselect.setAttribute('size', 1);
myselect.attachEvent('onchange', go);

b = 0;
while (myitems[a][b] != undefined)
{
myselect.options[myselect.length] = new Option(myitems[a][b][0], myitems[a][b][1]);
b++;
}
parentobj.appendChild(myselect);
a++;
}
}

function go()
{
ob = event.srcElement;
alert(ob.value);
}

Reply With Quote
  #5  
Old February 24th, 2006, 01:16 AM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: DOM/Adding elements and events

Cool. Good stuff to know...

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > DOM/Adding elements and events


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT