•
•
•
•
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
![]() |
•
•
Join Date: Jan 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I create dynamic bottom like this:
after this I can see button.
Next code line not working on IE only, why? And where is mistake
formElement = document.createElement('input');
formElement.setAttribute("type", "button");Next code line not working on IE only, why? And where is mistake
formElement.setAttribute("onClick", "buttonfunction()");•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
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
> 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.
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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation:
Rep Power: 0
Solved Threads: 32
> 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.
> 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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
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.
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- Array (C++)
- Open In New Window Php (PHP)
- SP2 problems (Windows NT / 2000 / XP / 2003)
- Change "<table..." definition with preg_replace_callback (PHP)
- Function Error Message Help (C++)
- Structure Help Please (C++)
- Error Creating Folder message during installation (OS X)
- phpBB thread archive (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: urgently need help!!!
- Next Thread: Problem with ajax and mozilla browser



Linear Mode