944,219 Members | Top Members by Rank

Ad:
May 18th, 2007
0

how to pass values to called function

Expand Post »
i used in this below code in usercontrol

but error happen

because the checkbox value didn't pass

please help how to pass the checkbox value

i try <!--onclick="checkedChanged(this,'checkbox')--> this line

but the checkbox is runat=server

so different value is generated in html view source code...

so doesn't work this code...........


function checkedChanged(PanelId,ChkID)
{
if(ChkID.checked == true)
{
PanelId.style.backgroundColor="Yellow";

return true;

}
if(ChkID.checked == false)
{
PanelId.style.backgroundColor="YellowGreen";
}
return false;

}


<div id="Panel1" style="WIDTH: 64px; HEIGHT: 48px; BACKGROUND-COLOR: yellowgreen" onclick="checkedChanged(this,checkbox) runat="server">
<img id="imgcolor" style="WIDTH: 32px; HEIGHT: 31px" height="31" src="file:///\\system107\HIS\Images\seat2.jpg"
width="32" align="middle" runat="server">
<input type="checkbox" id="Checkbox1" name="Checkbox1" runat="server">
<label id="Label1" runat="server"></label>
</div>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thirunavukaras is offline Offline
23 posts
since May 2007
May 18th, 2007
0

Re: how to pass values to called function

This is question for ASP.NET not for Javascript..
http://www.daniweb.com/techtalkforums/forum18.html
Reputation Points: 9
Solved Threads: 1
Newbie Poster
smalldog is offline Offline
20 posts
since May 2007
May 18th, 2007
0

Re: how to pass values to called function

i want to pass the aruments value in javascript
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thirunavukaras is offline Offline
23 posts
since May 2007
May 19th, 2007
0

Re: how to pass values to called function

There are several things wrong.

- The div and img tags don't have an onclick attribute.

- None of those tags has a runat attribute. The html tag is the only tag with that attribute.

- The runat attribute works on only Microsoft browsers and servers.

- Most attribute catalogs mark runat as "not currentlysupported".

- the value "checkbox" does not exist at the div tag. You need to call the function from the input tag.
Last edited by MidiMagic; May 19th, 2007 at 9:21 pm.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
May 21st, 2007
0

Re: how to pass values to called function

thanks for your reply........

i am used usercontrol to placed many times

that is why i am using runat=server attribute


<div id="Panel1" style="WIDTH: 64px; HEIGHT: 48px; BACKGROUND-COLOR: yellowgreen" onclick="checkedChanged(this,Checkbox1)" runat="server">
<img id="imgcolor" name="img" style="WIDTH: 32px; HEIGHT: 31px" height="31" src="file:///\\system107\HIS\Images\seat2.jpg"
width="32" align="middle" runat="server">
<input type="checkbox"
onclick="javascript:var temp=this;alert(temp);"

id="Checkbox1" name="Checkbox1">
<label id="Label1" runat="server"></label>
</div>


i want to pass temp value to the onclick="checkedChanged(this,temp)"

how to pass the checlbox this value or temp value in that function..

please reply.......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thirunavukaras is offline Offline
23 posts
since May 2007
May 21st, 2007
0

Re: how to pass values to called function

First, please enclose your code in the code pseudocode tags (in square brackets), as I have done below. Otherwise, your code turns into zxnrbl through auto formatting.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <div id="Panel1" style="WIDTH: 64px; HEIGHT: 48px; BACKGROUND-COLOR: yellowgreen" onclick="checkedChanged(this,Checkbox1)" runat="server">
The above tag can't possibly work, for the following reasons:
- The div tag doesn't know how to use an onclick attribute, because a div box isn't a clickable object.
- The value "Checkbox1" is not defined in the scope the div tag can see. It should be in single quotes.
- The runat attribute must be in the html tag itself, not in the individual tags for web page elements.

I suggest totally removing the onclick and runat from this tag.

Now for the next tag:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <img id="imgcolor" name="img" style="WIDTH: 32px;
  2. HEIGHT: 31px" height="31"
  3. src="file:///\\system107\HIS\Images\seat2.jpg"
  4. width="32" align="middle" runat="server" />
There are numerous reasons why this tag doesn't work:
- Styles are always lowercase. Change the case in your styles attribute, or to make it better, put them in a style in the stylesheet.
- the runat tag is not defined for individual tags, but only for the html tag. Remove it and put it in the html tag.

Now for the next tag:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <input type="checkbox"
  2. onclick="javascript:var temp=this;alert(temp);"
  3. id="Checkbox1" name="Checkbox1" />
It doesn't do anything except tell you where you are! As soon as you leave the Javascript part of the onclick in this tag, the value of the variable declared in it can be forgotten. It is not guaranteed to carry over to other JavaScript calls (some browsers do, some don't). Only global variables and the contents of input elements are retained.

This is really where you need to call your checkedChanged function, instead of in the div. Then, in the Javascript, refer to the background color of the div by using its complete variable description, including its id. You can pass it as a parameter in single quotes.

The last tags:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <label id="Label1" runat="server"></label>
  2. </div>
The runat attribute is not defined here either.

Quote ...
i want to pass temp value to the onclick="checkedChanged(this,temp)"

how to pass the checlbox this value or temp value in that function..

please reply.......
The problem is that you are calling the function from the wrong tag. Call it from the input tag.
Last edited by MidiMagic; May 21st, 2007 at 3:57 pm.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
May 22nd, 2007
0

Re: how to pass values to called function

I'm not disputing the validity of the rest of your post; but:

Quote originally posted by MidiMagic ...
- The div tag doesn't know how to use an onclick attribute, because a div box isn't a clickable object.
The onclick attribute can be given, correctly, on (almost) every visible element.
See http://www.w3schools.com/jsref/jsref_onclick.asp for a full list.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
May 22nd, 2007
0

Re: how to pass values to called function

Click to Expand / Collapse  Quote originally posted by MattEvans ...
I'm not disputing the validity of the rest of your post; but:

The onclick attribute can be given, correctly, on (almost) every visible element.
See http://www.w3schools.com/jsref/jsref_onclick.asp for a full list.
Thank you.

Apparently there is an omission in my favorite reference book that left div out of the list of tags which can use the set of standard events. I tried it, and it works. I annotated the list in my book.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Email validation using java script
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamic population of second list box based on the selection of first list box from s





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC