how to pass values to called function

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2007
Posts: 23
Reputation: thirunavukaras is an unknown quantity at this point 
Solved Threads: 0
thirunavukaras thirunavukaras is offline Offline
Newbie Poster

how to pass values to called function

 
0
  #1
May 18th, 2007
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>
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 20
Reputation: smalldog is an unknown quantity at this point 
Solved Threads: 1
smalldog smalldog is offline Offline
Newbie Poster

Re: how to pass values to called function

 
0
  #2
May 18th, 2007
This is question for ASP.NET not for Javascript..
http://www.daniweb.com/techtalkforums/forum18.html
Join a forum for webmasters and developers
HTML Forum
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 23
Reputation: thirunavukaras is an unknown quantity at this point 
Solved Threads: 0
thirunavukaras thirunavukaras is offline Offline
Newbie Poster

Re: how to pass values to called function

 
0
  #3
May 18th, 2007
i want to pass the aruments value in javascript
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: how to pass values to called function

 
0
  #4
May 19th, 2007
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.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 23
Reputation: thirunavukaras is an unknown quantity at this point 
Solved Threads: 0
thirunavukaras thirunavukaras is offline Offline
Newbie Poster

Re: how to pass values to called function

 
0
  #5
May 21st, 2007
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.......
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: how to pass values to called function

 
0
  #6
May 21st, 2007
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.

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.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: how to pass values to called function

 
0
  #7
May 22nd, 2007
I'm not disputing the validity of the rest of your post; but:

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.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: how to pass values to called function

 
0
  #8
May 22nd, 2007
Originally Posted by MattEvans View Post
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.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC