473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

function setColor(color)

I'm attempting to use Javascript (function setColor(color)) with a popup color picker. I need to set the color for at least 2 page attributes. My first attempt is cross browser compatible, but limited to 1 field.

<script type="text/javascript">
function setColor(color){
if (opener && !opener.closed){
opener.document.theForm.theField.value = color;
opener.focus();
}
window.close();
}
</script>

My second attempt works for Firefox, but not for Internet Explorer.

<script type="text/javascript">
function setColor(color)
{
if (opener && !opener.closed && opener.setTargetField)
{
opener.setTargetField(targetField, color.toUpperCase());

}
window.close();
}
</script>

Any help will be greatly appreciated.
Jun 16 '07 #1
6 7941
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Can you post the parent window code or at least setTarget.
Jun 18 '07 #2
Greetings!

Maybe it would be easier to start off with DOM, window.opener.document.getElementById, but I'm not familiar with it.

<script type="text/javascript">

function openColorPicker(targetField){

var w = window.open('WriteTable.html','color_popup','width =400,height=450,scrollbars=0');
w.targetField = targetField; //create target field variable in popup window with the passed targetField as value
w.focus();
return false;
}

//callback function
function setTargetField(targetField, color){
if (targetField){
targetField.value = color;
}
window.focus();
}
</script>

<form name="theForm" action="javascript:setColors()" style="margin:0;">

Background color:
<br><input name="bgcolorbox" type="text" class="colorbox" maxlength="6" onChange="setColors()" readonly="readonly"><br \>
<a href="" onclick="return openColorPicker(document.theForm.bgcolorbox)">chan ge color</a><br />
<br>&nbsp;
<br>Font color:
<br><input name="fontcolorbox" type="text" class="colorbox" maxlength="6" onChange="setColors()" readonly="readonly"><br \>
<a href="" onclick="return openColorPicker(document.theForm.fontcolorbox)">ch ange color</a><br />

<br><input type="submit" value="Set Colors" class="subtn">

<br></form>
Jun 19 '07 #3
acoder
16,027 Expert Mod 8TB
Do you get an error in IE? What you could try doing instead is to pass a string (the id of the form field). This means you will have to set the ID for each form element. Then to set the color, you could use:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(targetFieldID).value = color;
Jun 20 '07 #4
acoder,

You agree with my earlier statement. I stated earlier that I have not ever used the required javascript, so I don't know how to return the value to the parent page or how to write the callback function. Please show the full script and not just a snippet. This is an example of my popup cells.

<td id="cell" 0_0="" onclick='javascript:setColor("#FFFFFF");' bgcolor="#ffffff" height="25" width="30"></td>

Thanks in advance.
Jun 20 '07 #5
acoder
16,027 Expert Mod 8TB
So does IE give an error?

Try adding a var targetField at the beginning of the popup.
Jun 20 '07 #6
I'm sorry that I forgot to inform you that it is errorless.
Jun 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: pablo | last post by:
Dear Newsgroupers, The 'main' page contains a call to a function in an included file. This function puts a html-form on the screen. Before the form gets posted (to the 'main' page) some prior...
10
by: Brad Tilley | last post by:
Is there an easier way to do this: def print_whats_returned(function): print function print type(function)
3
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
7
by: MALdito | last post by:
hi everybody let me say right from the start .. I´m not a coder ... "just" a designer! that said .. here is my question: I´m using dreamweaver´s built in preloader for a menu. it looks like...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
8
by: Ares Lagae | last post by:
When adopting the coding style of the standard C++ library, you often run into naming problems because class names are lower case, and member functions do not have get/set prefixes. For example:...
1
by: TomHL | last post by:
hello, the code below make a bitmap greyscale. how do I change the code that the result will be 16 colors/256 colors instead of greyscale? somebody can explain the theory behind the...
0
by: alwayssmiling | last post by:
Hi All, In my class im reading each and every cell with the help of indexes like .... . From this im reading the Color value of that cell. Now i want to assign this color value to some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.