Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.getElementById "Style" busted in IE and Safari

    This seems to be a common problem however after probing the internet for a few hours I can't seem to find a suitable solution.

    This code "document.getElementById('id').style.color='color')"works just fine in Firefox, Netscape Navigator and Opera, but not in IE or Safari. I'm also having a problem with the borderColor, but I assume it's an all encompassing browser related problem.

    I've run the code through a validator so I know that isn't an issue, I'm completely befuddled. Here's my abridged code, I've bolded the problem areas.

    Code:
                                    <div id="orientation1" style="position:relative; width:*px; height:*px; top:0px; left:0px; visibility:visible;" >
    
    					<div id="photo1" style="position:absolute; width:225px; height:275px; left:50px; top:50px; Color:#000000;  border-style:solid; border-color:#000000; border-width:1px; 1px; 1px; 1px;" align="center">			
    					         Cover Image(s)
    					</div>
    					<div id="text1" style="position:absolute; width:150px; height:150px; left:312px; top:115px; Color:#000000;  border-style:dashed; border-color:#000000; border-width:1px; 1px; 1px; 1px;" align="center">			
    						<font size="6">Text</font><br>
    
    						<font size="5">Text</font><br>
    						<font size="4">Text</font><br>			
    						<font size="3">Text</font><br>
    						<font size="2">Text</font><br>
    
    		
    
    					</div>
    				</div>
    	
    				<div id="orientation2" style="position:relative; width:*px; height:*px; top:0px; left:0px; visibility:hidden;">
    
    					<div id="photo2" style="position:absolute; width:300px; height:200px; left:100px; top:30px; Color:#000000;  border-style:solid; border-color:#000000; border-width:1px; 1px; 1px; 1px;" align="center">			
    						Cover Image(s)
    					</div>
    					<div id="text2" style="position:absolute; width:200px; height:95px; left:150px; top:250px; Color:#000000;  border-style:dashed; border-color:#000000; border-width:1px; 1px; 1px; 1px;" align="center">			
    						<font size="6">Text</font><br>
    						<font size="4">Text</font><br>
    						<font size="2">Text</font><br>
    						<font size="1">Text</font><br>
    
    					</div>
    				</div>
    
    
    
    
    <select name="font_color">
            <option value="Black" selected="selected" onclick="(document.getElementById('text1').style.color='#000000')&&(document.getElementById('text2').style.color='#000000')&&(document.getElementById('photo1').style.color='#000000')&&(document.getElementById('photo2').style.color='#000000');">Black</option>
            <option value="White" onclick="(document.getElementById('text1').style.color='#ffffff')&&(document.getElementById('text2').style.color='#ffffff')&&(document.getElementById('photo1').style.color='#ffffff')&&(document.getElementById('photo2').style.color='#ffffff');">White</option>
            <option value="Sienna" onclick="(document.getElementById('text1').style.color='#b3572a')&&(document.getElementById('text2').style.color='#b3572a')&&(document.getElementById('photo1').style.color='#b3572a')&&(document.getElementById('photo2').style.color='#b3572a');">Sienna</option>
            <option value="Gold" onclick="(document.getElementById('text1').style.color='#e9d924')&&(document.getElementById('text2').style.color='#e9d924')&&(document.getElementById('photo1').style.color='#e9d924')&&(document.getElementById('photo2').style.color='#e9d924');">Gold</option>
            <option value="Accent From Background" onclick="(document.getElementById('text1').style.color='#e9d924')&&(document.getElementById('text2').style.color='#e9d924')&&(document.getElementById('photo1').style.color='#e9d924')&&(document.getElementById('photo2').style.color='#e9d924');">Accent From Background</option>
    </select>

    Strangely though, I'm not having a problem with the following similar code...

    Code:
    						<table>
    							<tr>
    								<td align="center">
    									<img src="images/vertical.gif" border="0" alt=""><br>				
    									Vertical<br>
    									<input type="radio" name="photoorientation" value="vertical" checked="checked" onclick="(document.getElementById('orientation1').style.visibility='visible') && (document.getElementById('orientation2').style.visibility='hidden');">
    								</td>
    								<td width="30">
    								</td>
    								<td align="center">
    									<img src="images/horizontal.gif" border="0" alt=""><br>
    									Horizontal<br>
    									<input type="radio" name="photoorientation" value="horizontal" onclick="(document.getElementById('orientation1').style.visibility='hidden') && (document.getElementById('orientation2').style.visibility='visible');">
    								</td>
    							</tr>
    						</table>
    Thanks for the help,
    infl8
    Last edited by infl8; 03-13-2008 at 07:25 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Its not document.getElementById causing the issue. Its the onclick in the option. Some browsers don't allow the onclick event in option elements. You should be using onchange in the select element.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I did some further research and got it all to work out.

    -infl8


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •