User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,678 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1283 | Replies: 10
Reply
Join Date: Jan 2008
Posts: 1
Reputation: bogdangwawa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bogdangwawa bogdangwawa is offline Offline
Newbie Poster

Question Change function in bottom

  #1  
Jan 21st, 2008
I create dynamic bottom like this:
formElement = document.createElement('input');
formElement.setAttribute("type", "button");
after this I can see button.
Next code line not working on IE only, why? And where is mistake
formElement.setAttribute("onClick",  "buttonfunction()");
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 2
Reputation: xyzweb is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xyzweb xyzweb is offline Offline
Newbie Poster

Re: Change function in bottom

  #2  
Jan 22nd, 2008
Internet Explorer will not let you set inline event handlers using the DOM .setAttribute() method (see this bug report):
http://webbugtrack.blogspot.com/2007...ways-work.html

You also can't set the name of the field (if you wanted to) due to this bug:
http://webbugtrack.blogspot.com/2007...ken-in-ie.html

Rumor has it that both of these bugs will be fixed in IE8.

HTH
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,851
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Change function in bottom

  #3  
Jan 23rd, 2008
IE doesn't like setAttribute as already mentioned. A cross browser compatible way of setting the attributes would be to treat them as object properties and modify them directly.

formElement.type = "button";
/* .... */
formElement.onclick = function() {
   someFunction();
}
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jan 2008
Posts: 2
Reputation: xyzweb is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xyzweb xyzweb is offline Offline
Newbie Poster

Re: Change function in bottom

  #4  
Jan 23rd, 2008
The only trick is, that:
formElement.type = '?';
//only works in IE before you append the element to the DOM

formElement.onclick = function(){...}
//does work, although you can't append multiple event handlers nicely.  Using a cross browser addEvent() method is a much more desired approach.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,556
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 114
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Change function in bottom

  #5  
Jan 25th, 2008
This seems to me to be doing things the hard way.

What's wrong with using a simple button object that always calls the same function? Then use if statements in the function to determine what the button should do (including nothing). It seems a lot easier than playing with attributes in the page elements.

Playing with the page attributes for this purpose seems to me like using a 10-ton hydraulic press to crack a peanut out of its shell.
Last edited by MidiMagic : Jan 25th, 2008 at 10:18 pm.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,851
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Change function in bottom

  #6  
Jan 25th, 2008
> What's wrong with using a simple button object that always calls the same function?
So what happens when tomorrow the requirement changes and you are told to add five more buttons dynamically? With the approach he is using, he would just have to invoke the function which renders a button five times.

But using your approach, it would mean adding five new blocks to the *ugly* if-else ladder not to mention brining hell to the maintenance programmer just because the logic which you used was not intuitive and obvious.

> Playing with the page attributes for this purpose seems to me like using a 10-ton hydraulic press to
> crack a peanut out of its shell.
Quite the opposite, it lends to a more elegant solution over a kludgey one.
Last edited by ~s.o.s~ : Jan 25th, 2008 at 10:27 pm.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,556
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 114
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Change function in bottom

  #7  
Jan 25th, 2008
It seems kludgy to me to change the attributes of the page.

It is not at all elegant, and makes debugging harder.

It reeks of self-modifying code.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 32
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: Change function in bottom

  #8  
Jan 26th, 2008
dom approach has its own beauty.........it has solved many problems..
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,851
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Change function in bottom

  #9  
Jan 26th, 2008
> It seems kludgy to me to change the attributes of the page.
> It is not at all elegant, and makes debugging harder.
> It reeks of self-modifying code.
Clearly you are ignorant of how professional Javascript code is written. Try to write something useful without *changing the attributes of the page* or writing *self modifying code* and you might just see the light. Not using the higher level abstractions provided by the language / API is just plain foolishness.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,556
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 114
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Change function in bottom

  #10  
Jan 28th, 2008
Changing page attributes to display something different is one thing.

Changing what function a button calls seems to me to be very hard to debug. This is especially true if you are expecting the button to be calling one function, and it is actually calling another one, due to a page attribute modification you forgot about, or didn't expect to happen.

If you use a global variable and a conditional statement to select what the button does, it's amazingly easy to find the trouble.

The grading policy at the college I work at counts off heavily if someone writes self-modifying code or uses page attribute changes to control program flow.
Last edited by MidiMagic : Jan 28th, 2008 at 9:58 pm.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC