Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox value

Status
Not open for further replies.

kristolcrawley

Programmer
Jun 17, 2002
19
US
I have a list displaying part information. On each line there's a checkbox. When the user clicks on the check box, which I named the index value for that line, I'm calling a function that will display a page with more detail about the part. It works great but whether you check or uncheck the box you still get the page. I tried testing for val.checked but that isn't working. What the heck am I doing wrong??

<TD><INPUT TYPE=&quot;checkbox&quot; NAME=&quot;param:index&quot; VALUE=&quot;moreInfo&quot; onClick=&quot;showInfo(this.name);&quot;></TD>


function showInfo (blah){
//var indVal = document.forms.value;
alert(&quot;this index is: &quot; + blah);
var mainId = 0;
var subId = 0;
var windowwidth = 800, topheight = 600, bottomheight = 10; // default sizes
if (window.screen) {
windowwidth = window.screen.availWidth-10;
topheight = (window.screen.availHeight * 60 / 100) - 10;
bottomheight = (window.screen.availHeight * 40 / 100) - 20;
}
var UHJ = 'contractInfo.jhtml?mainId=' + mainId + '&subId=' + subId;
alert(&quot;clicky: &quot; + blah.checked);

window.open(UHJ,'test','scrollbars=yes');
}
 
You are passing this.name to the function.

Pass this (i.e. onClick=&quot;showInfo(this);&quot;)
this passes a reference to the checkbox object.
You can then check the value to see if it is checked:
blah.checked

use this code for testing

<TD><INPUT TYPE=&quot;checkbox&quot; NAME=&quot;param:index&quot; VALUE=&quot;moreInfo&quot; onClick=&quot;showInfo(this);&quot;></TD>

<script language=&quot;javascript&quot;>
function showInfo (blah){
//var indVal = document.forms.value;
alert(&quot;this index is: &quot; + blah);
var mainId = 0;
var subId = 0;
var windowwidth = 800, topheight = 600, bottomheight = 10; // default sizes
if (window.screen) {
windowwidth = window.screen.availWidth-10;
topheight = (window.screen.availHeight * 60 / 100) - 10;
bottomheight = (window.screen.availHeight * 40 / 100) - 20;
}
var UHJ = 'contractInfo.jhtml?mainId=' + mainId + '&subId=' + subId;
alert(&quot;clicky: &quot; + blah.checked);

//zwindow.open(UHJ,'test','scrollbars=yes');

}
</script>
 
Thanks Sark. I did try this and it works but then I no longer have the index value. Without this I don't know which line I'm on so I can't pass the part detail. Isn't there a way to accomplish both??!!
 
use a reference to blah.name inside your javascript function and you shouldn't have any problem

-kaht

banghead.gif
 
Since you have a reference to the object passed into the function, you can get any value associated with the object.
You can get its name(part detail) in your function as so:

<script language=&quot;javascript&quot;>
function showInfo (blah){
//var indVal = document.forms.value;


alert(&quot;this index is: &quot; + blah.name);




var mainId = 0;
var subId = 0;
var windowwidth = 800, topheight = 600, bottomheight = 10; // default sizes
if (window.screen) {
windowwidth = window.screen.availWidth-10;
topheight = (window.screen.availHeight * 60 / 100) - 10;
bottomheight = (window.screen.availHeight * 40 / 100) - 20;
}
var UHJ = 'contractInfo.jhtml?mainId=' + mainId + '&subId=' + subId;
alert(&quot;clicky: &quot; + blah.checked);

//zwindow.open(UHJ,'test','scrollbars=yes');

}
</script>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top