Register    Login    Forum    Search    FAQ

Board index » Programming » JavaScript




 Page 1 of 1 [ 7 posts ] 



Author Message
 Post subject: randomly change color when refresh it...IE problem
 Post Posted: Wed Jan 30, 2013 11:26 am 
Offline
Forum Veteran
Forum Veteran
User avatar

Joined: Sat May 22, 2010 10:03 am
Posts: 183
Location: Malaysia
Languages: C(Basic), JAVA(Learning), PHP, HTML, CSS, JAVASCRIPT, XML, JQUERY, AJAX
Text editor: Notepad++
it works perfectly on chrome and firefox, but doesn't work on IE. Any solution, or other ways to perform the same result? Thanks ;)

javascript code:
$(document).ready(function() {
       
        var colorlist = new Array("#e0c062" ,  "#007fff" , "#009dff" , "#e246c1" , "#f91b61" ,  "#00c93c");
        var topic = document.getElementsByName('topic');
 
        for (i=0; i<topic.length; i++) {
                var color = colorlist[Math.floor(Math.random() * colorlist.length)];
                topic.item(i).style.backgroundColor=color;
        }
       
});

_________________
The Language That I'm Learning

JavaScript
Html(Xhtml)
Css


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Wed Jan 30, 2013 1:17 pm 
Offline
Hero of the Forum
Hero of the Forum
User avatar

Joined: Tue Nov 13, 2012 4:37 pm
Posts: 1023
Location: Serbia
Languages: C/C++ HTML CSS JavaScript PHP BasicsOf: Java Assembly SQL
Text editor: Sublime text
I found that problem is here topic.item(i).style.backgroundColor=color;
But I don't think it can be fixed. But that's not important, noone uses IE anymore anyway.

_________________
Every problem has a solution.
.
Currently working on: RoyalWars


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Wed Jan 30, 2013 10:23 pm 
Offline
Forum Veteran
Forum Veteran
User avatar

Joined: Sat May 22, 2010 10:03 am
Posts: 183
Location: Malaysia
Languages: C(Basic), JAVA(Learning), PHP, HTML, CSS, JAVASCRIPT, XML, JQUERY, AJAX
Text editor: Notepad++
thank you zoran404, but i will still try it out first... if really cant i will just leave it there.... haha
anywhere, i still got another problem on ie -.- .... is about jquery trigger function....

something like this...

$('#upload').change(function () {
$('#submit').trigger('click');
)};

_________________
The Language That I'm Learning

JavaScript
Html(Xhtml)
Css


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Thu Jan 31, 2013 1:07 am 
Offline
Expert Poster
Expert Poster

Joined: Fri Dec 14, 2012 12:06 pm
Posts: 108
Languages: Java, C/C++/C#, Node.js, Javascript, jQuery
Text editor: Aptana
Try:
jquery code:
$("#submit").click();


About the IE problem, have you tried to use jQuery instead of pure JS?
jquery code:
var topic = $(".topic"); // have anything against adding a class?
topic.each(function(){
  var color = colorlist[Math.floor(Math.random() * colorlist.length)];
  $(this).css("backgroundColor", color);
});


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Thu Jan 31, 2013 2:14 am 
Offline
Forum Veteran
Forum Veteran
User avatar

Joined: Sat May 22, 2010 10:03 am
Posts: 183
Location: Malaysia
Languages: C(Basic), JAVA(Learning), PHP, HTML, CSS, JAVASCRIPT, XML, JQUERY, AJAX
Text editor: Notepad++
Thanks DFA1. The color problem work ... but the $('#submit').click(); still not work :'(

_________________
The Language That I'm Learning

JavaScript
Html(Xhtml)
Css


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Thu Jan 31, 2013 8:30 am 
Offline
Hero of the Forum
Hero of the Forum
User avatar

Joined: Tue Nov 13, 2012 4:37 pm
Posts: 1023
Location: Serbia
Languages: C/C++ HTML CSS JavaScript PHP BasicsOf: Java Assembly SQL
Text editor: Sublime text
DFA1 wrote:
About the IE problem, have you tried to use jQuery instead of pure JS?
jquery code:
var topic = $(".topic"); // have anything against adding a class?
topic.each(function(){
  var color = colorlist[Math.floor(Math.random() * colorlist.length)];
  $(this).css("backgroundColor", color);
});

backgroundColor insted of background-color, should have remembered that. quess I don't practice js enough.

_________________
Every problem has a solution.
.
Currently working on: RoyalWars


Top 
 Post subject: Re: randomly change color when refresh it...IE problem
 Post Posted: Sat Feb 02, 2013 4:59 am 
Offline
Expert Poster
Expert Poster

Joined: Fri Dec 14, 2012 12:06 pm
Posts: 108
Languages: Java, C/C++/C#, Node.js, Javascript, jQuery
Text editor: Aptana
Are you sure your change callback function is called? Try to add an alert inside it and see if you get it.

From jQuery change docs:
As of jQuery 1.4, the change event bubbles in Internet Explorer, behaving consistently with the event in other modern browsers.

The .click() should do the trick.

Let me know what happened.

p.s. Your submit button is inside a form? If the answer is yes and you don't trust the click trigger, try to submit the form. Have a look:
http://api.jquery.com/submit/


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 7 posts ] 




Board index » Programming » JavaScript


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron