| | |
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
![]() |
•
•
Join Date: May 2007
Posts: 23
Reputation:
Solved Threads: 0
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>
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>
•
•
Join Date: May 2007
Posts: 20
Reputation:
Solved Threads: 1
This is question for ASP.NET not for Javascript..
http://www.daniweb.com/techtalkforums/forum18.html
http://www.daniweb.com/techtalkforums/forum18.html
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.
- 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
•
•
Join Date: May 2007
Posts: 23
Reputation:
Solved Threads: 0
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.......
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.......
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.
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:
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:
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:
The runat attribute is not defined here either.
The problem is that you are calling the function from the wrong tag. Call it from the input tag.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<div id="Panel1" style="WIDTH: 64px; HEIGHT: 48px; BACKGROUND-COLOR: yellowgreen" onclick="checkedChanged(this,Checkbox1)" runat="server">
- 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)
<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" />
- 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)
<input type="checkbox" onclick="javascript:var temp=this;alert(temp);" id="Checkbox1" name="Checkbox1" />
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)
<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.......
Last edited by MidiMagic; May 21st, 2007 at 3:57 pm.
Daylight-saving time uses more gasoline
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.
•
•
•
•
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.
See http://www.w3schools.com/jsref/jsref_onclick.asp for a full list.
Plato forgot the nullahedron..
•
•
•
•
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.
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
![]() |
Similar Threads
- how to pass values to called function (ASP.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Email validation using java script
- Next Thread: Dynamic population of second list box based on the selection of first list box from s
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically beta box bug calendar cart checkbox class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element embed enter error explorer firefox focus frameworks getselection google gwt hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseover parent paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c website window windowofwords windowsxp wysiwyg \n






