Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 27-01-2009, 09:34 PM   #1 (permalink)
In The Zone
 
Sridhar_Rao's Avatar
 
Join Date: Feb 2007
Posts: 353
Default changing the background of element on the fly using javascript


Hello,

I wish to change the background color plus the text color of a form element on the fly using javascript. When click on a link, not only the focus should be on the element but the background colour and font colour too should change.

I experimented using getElementById property and it worked well in firefox and chrome but not in IE 7.

How can this be done?
__________________
Want to study M.Sc in any medical subjects? Read this www.microrao.com/msc.htm
Microx, a diagnostic microbiology laboratory software application www.labmicrox.com
Sridhar_Rao is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 27-01-2009, 11:05 PM   #2 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: changing the background of element on the fly using javascript

In the status bar, near the left corner it may be hinting towards some error. Check it out!
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता
victor_rambo is offline  
Old 28-01-2009, 01:32 PM   #3 (permalink)
spice it up
 
kapsicum's Avatar
 
Join Date: Apr 2004
Location: mumbai
Posts: 106
Thumbs up Re: changing the background of element on the fly using javascript

its better if u could show the code ...

well you can do in following way :

1. Create a new style class which may be something like this :

Code:
.newClass {
	background-color: #003399;
	color: #FFFFFF;
}
2. Add a javascript function something like this :

Code:
function changeClass(element) {
	var elementObj = document.getElementById(element);
	elementObj.focus();
	elementObj.className = 'newClass';
}
3. Call the function onClick of an element something like this :
Code:
<a href="javascript:void(0);" onClick="javscript: changeClass('formElementId');" >Sometext</a>

Last edited by kapsicum; 28-01-2009 at 01:54 PM. Reason: Automerged Doublepost
kapsicum is offline  
Old 02-02-2009, 08:07 PM   #4 (permalink)
In The Zone
 
Sridhar_Rao's Avatar
 
Join Date: Feb 2007
Posts: 353
Default Re: changing the background of element on the fly using javascript

Thanks a lot Kapsicum, this is exactly what I was looking for.
__________________
Want to study M.Sc in any medical subjects? Read this www.microrao.com/msc.htm
Microx, a diagnostic microbiology laboratory software application www.labmicrox.com
Sridhar_Rao is offline  
Old 02-02-2009, 08:36 PM   #5 (permalink)
tHe nEw gEEk......ITian
 
pr.itdude's Avatar
 
Join Date: Oct 2008
Location: New Delhi
Posts: 358
Default Re: changing the background of element on the fly using javascript

hey i too need someones help.....

actually i need a code/javascript so that whenever user opens the page of my blog (blogspot), and if the user's screen resolution is 600x800 pixels then the horizontal scroll bar (below) of the window, comes in the middle. And if the screen resolution is 1024x768 pixels or more then the page should open normally i.e., this code then should not be executed.!!

Thnx. waiting eagerly of some help!!
pr.itdude is offline  
Old 04-02-2009, 05:13 PM   #6 (permalink)
spice it up
 
kapsicum's Avatar
 
Join Date: Apr 2004
Location: mumbai
Posts: 106
Thumbs up Re: changing the background of element on the fly using javascript

Quote:
Originally Posted by pr.itdude View Post
hey i too need someones help.....

actually i need a code/javascript so that whenever user opens the page of my blog (blogspot), and if the user's screen resolution is 600x800 pixels then the horizontal scroll bar (below) of the window, comes in the middle. And if the screen resolution is 1024x768 pixels or more then the page should open normally i.e., this code then should not be executed.!!

Thnx. waiting eagerly of some help!!
cant imagine y do u want to do dat but try the following :

Code:
<script type="text/javascript"> 
function moveHorizontalScroll() {
	if(screen.width == 800 && screen.height == 600) //check for users Screen Resolution
	{
		var browserWidth ,browserHeight;
		//get the Browser's Inner Dimentions 
		if(window.innerHeight || window.innerWidth) {  // FF, Chrome, Safari
			browserWidth = window.innerWidth;
			browserHeight = window.innerHeight;
		}
		else { // IE
			browserWidth = document.documentElement.clientWidth;
			browserHeight = document.documentElement.clientHeight;
		}
		var midPos = Math.round(browserWidth / 2); // set to half of the browser's inner width .... change as u feel the need
		window.scroll(midPos,0); // Horizontal ,Vertical scroll position in pixels
	}
}
</script>
then call the function on body onload as follows :

Code:
<body onload="moveHorizontalScroll()">
kapsicum is offline  
Old 04-02-2009, 07:48 PM   #7 (permalink)
tHe nEw gEEk......ITian
 
pr.itdude's Avatar
 
Join Date: Oct 2008
Location: New Delhi
Posts: 358
Default Re: changing the background of element on the fly using javascript

thnx ^^.......
actually its the template of my blog which forced me to do this........
pr.itdude is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing background music of video files R2K Software Q&A 6 28-09-2008 09:13 PM
Help me to add a page element to my blog gurujee QnA (read only) 5 28-03-2008 09:16 AM
new element in peridioc table :) chicha Chit-Chat 14 26-02-2008 09:12 AM
desktop background is not changing vijay_ss2004 Software Q&A 8 09-12-2007 03:00 PM
Changing label text using javascript whoopy_whale QnA (read only) 2 18-06-2007 10:20 AM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 03:06 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2