Passing argurment preventing function from running

T

tshad

I have a ColorPicker program I found on the net that I am modifying to work
with mulitple objects on my page. I can't seem to get this to work if I
pass the object I want it to change. It works fine if I don't pass it
anything in this the picker.show() method.

I thought maybe it was because I was passing a asp:TextBox as an object.
But when I changed it to only use an "input" object I am having the same
problem.

I cut the program and .js file down to nothing to see what the problem and
found that it doesn't even get into the picker.show() method if I pass a
value. I have an "alert" as the only thing in the picker.show() function
and it will not execute if something is passed.

Here are the 2 files that work.
***********************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript"
src="testObject.js"></script>
<script language="javascript">
function pickerCallback(hexcolor) {
alert("In pickerCallback");
}
picker = new ColorPicker('picker', 'pickerCallback');
</script>
</head>
<body>
<form action="" method="get" name="form1">
<input name="color" type="text" disabled="true" size="8"
maxlength="7">&nbsp;
<a href="javascript:picker.show()"><img src="/images/icon.gif"
border="0"/></a>
</form>
</body>
</html>
******************************************************************

testObject.js
**************************************************
function ColorPicker(objName, callbackFunc) {
/**
* Properties
*/
this.objName = objName;
this.callbackFunc = callbackFunc;
this.show = ColorPicker_show;
}

function ColorPicker_show()
{
alert("Inside ColorPicker_show");
}
**********************************************************

Here are the 2 files that don't work. The only thing different is the
"ColorPicker_show(me)" in the .js file and the
href="javascript:picker.show(color)" in the link.

****************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript"
src="testObject.js"></script>
<script language="javascript">
function pickerCallback(hexcolor) {
alert("In pickerCallback");
}
picker = new ColorPicker('picker', 'pickerCallback');
</script>
</head>
<body>
<form action="" method="get" name="form1">
<input name="color" type="text" disabled="true" size="8"
maxlength="7">&nbsp;
<a href="javascript:picker.show(color)"><img src="/images/icon.gif"
border="0"/></a>
</form>
</body>
</html>
****************************************************************

testObject.js
****************************************************************
function ColorPicker(objName, callbackFunc) {
/**
* Properties
*/
this.objName = objName;
this.callbackFunc = callbackFunc;
this.show = ColorPicker_show;
}

function ColorPicker_show(me)
{
alert("Inside ColorPicker_show");
}
****************************************************************

Am I not calling the function correctly?

Thanks,

Tom
 
P

pr

tshad said:
I have a ColorPicker program I found on the net that I am modifying to work
with mulitple objects on my page. I can't seem to get this to work if I
pass the object I want it to change. It works fine if I don't pass it
anything in this the picker.show() method. [...]
<form action="" method="get" name="form1">
<input name="color" type="text" disabled="true" size="8"
maxlength="7">&nbsp;
<a href="javascript:picker.show(color)"><img src="/images/icon.gif"
border="0"/></a>
</form>
</body>
</html>
[...]

1. Looks like you're expecting the word 'color' to magically represent
the content of the input box. It won't unless you make it so.

2. Avoid javascript urls.

You might try:

<a href="noscript.htm" onclick="return
picker.show(document.forms['form1'].elements['color'].value)">...

see http://jibbering.com/faq/#FAQ4_13
 
T

tshad

pr said:
tshad said:
I have a ColorPicker program I found on the net that I am modifying to
work
with mulitple objects on my page. I can't seem to get this to work if I
pass the object I want it to change. It works fine if I don't pass it
anything in this the picker.show() method. [...]
<form action="" method="get" name="form1">
<input name="color" type="text" disabled="true" size="8"
maxlength="7">&nbsp;
<a href="javascript:picker.show(color)"><img src="/images/icon.gif"
border="0"/></a>
</form>
</body>
</html>
[...]

1. Looks like you're expecting the word 'color' to magically represent the
content of the input box. It won't unless you make it so.

2. Avoid javascript urls.

You might try:

<a href="noscript.htm" onclick="return
picker.show(document.forms['form1'].elements['color'].value)">...

I'm not sure I understand what you are doing here.

I am trying to send a reference to the textbox "color" that I can access
using "me" in the function.

This was how other programs seem to do it.

Aren't you passing the value of "color" in your example, instead of the
object itself?

What I am going to be doing is picking a color from a grid and setting the
"color" (or some other box) value to the textboxes background color:

document.form1.color.style.backgroundColor = hexcolor

But in the above I need to replace "color" with "me".

The reason I am using the Javascript URL is because that is what the code I
used was doing. It was putting a Color Picker table on the screen to allow
a user to pick a color. Each square has a JavaScript URL on it that is
fired when the user selects the box.

Thanks,

Tom
 
P

pr

tshad wrote:
[...]
I am trying to send a reference to the textbox "color" that I can access
using "me" in the function.

Depending on what you want to do with it:

document.forms["form1"].elements["color"]

or (if you give the input box the ID 'color')

document.getElementById("color")

[...]
The reason I am using the Javascript URL is because that is what the code I
used was doing.

One should be careful what one downloads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top