...

View Full Version : display an alert messages recursively by clicking a checkbox



lettisha
08-21-2007, 08:16 AM
Hi,
Am using datagrid concept in a JSP page. When I click on a checkbox from the datagrid a timer will start. after 5mins I need to display an alert message along with an ID which is the value of that checkbox. like that I can click on any checkbox at any time. I've already implemented a code for it. when am clicking 2 checkboxes am getting 2 alert messages but with recently selected checkbox value instead of individual IDs.
Here is the script i've used

var s;
function SelRecord(forms,str) {

var max=eval("forms."+str+".length");
if (max)
{
for (var idx = 0; idx < max; idx++) {
if (eval("forms."+str+"[" + idx + "].checked") == true) {
s=forms.rd[idx].value;
var t=setTimeout('alert(s+"dilatation complete")',5000);
}
}
}
}

Please.... Can anyone gimme a solution for this.....

nikkiH
08-21-2007, 03:47 PM
Stop using eval. You don't need it and it's a hog. It doesn't perform well, especially in a loop, and it makes your code harder to read.

I'm not sure what your variables are supposed to stand for, but if str is the name of the select element and forms is the form element, you do this:

var max = forms.elements[str].options.length;

As to your question, you wanted the value, that's what you told it to do here:
s=forms.rd[idx].value;

If you wanted something else, like the ID, you need to use that property instead.

lettisha
08-22-2007, 09:08 AM
Thanku so much ur suggestion. I dono much bout Java Script. am still learning it.
actually we've a Data Grid. in the grid there will be many records with a checkbox in each row. when we click on the checkbox am sending an ID i.e. some MrNo as its value to the script. A timer starts when we click on the checkbox. after 5 seconds it'll give an alert message dat time is up for dat particular checkbox.
say suppose if am clicking on first record the timer starts and immediately if I click on another record before getting an alert message for previous checkbox then i need to get 2 alert messages for both the checkboxes separately. I am getting 2 alert messages. but in the alert messages am getting the value of recently checked checkbox. but i need to display values of both the checkboxes in 2 different alert messages after the timer.
here am attaching the code. please go thru it once.

<script type="text/javascript">
var s;
function RecSelect(forms,str) {
alert("STR Value:"+str);
var max=eval("forms."+str+".length");
alert("Max value:"+max);
if (max)
{

for (var idx = 0; idx < max; idx++) {


if (eval("forms."+str+"[" + idx + "].checked") == true) {
s=forms.rd[idx].value;
var t=setTimeout('alert(s+"dilatation complete")',5000);

alert(s);
}

}
}

}




</script>





<ui:dataGrid items="${rlist}" var="rd" name="datagrid1" cellPadding="0" cellSpacing="0" requestPath="<%=path%>" scroll="true" width="100%" styleClass="datagrid">
<columns>
<column width="20">

<item hAlign="center">
<![CDATA[
<input type="checkbox" name="rd" value="${rd.mrno}"/>
]]>
</item>
</column>
<column width="25%" order="true">
<header value="MR Number" hAlign="center" styleClass="header"/>
<item class="table_border_new" value="${rd.mrno}" hAlign="left"/>
<aggregate function="avg" var="total"/>
</column>
<column width="25%" order="true">
<header value="First Name" hAlign="center" styleClass="header"/>
<item class="table_border_new" value="${rd.fname}" hAlign="left" />
<aggregate function="avg" var="total"/>
</column>
<column width="25%" order="true">
<header value="Last Name" hAlign="center" styleClass="header"/>
<item class="table_border_new" value="${rd.lname}" hAlign="left" />
<aggregate function="avg" var="total"/>
</column>
<column width="25%" order="true">
<header value="Sex" hAlign="center" styleClass="header"/>
<item class="table_border_new" value="${rd.sex}" hAlign="left" />
<aggregate function="avg" var="total"/>
</column>

</columns>
<paging size="10" nextUrlVar="next" previousUrlVar="previous" pagesVar="pages"/>
<rows styleClass="rows" hiliteStyleClass="hiliterows"/>
<alternateRows styleClass="alternaterows"/>
<order imgAsc="./images/up.gif" imgDesc="./images/down.gif"/>
</ui:dataGrid>


<input type="button" class="BlueButton" style="width:90px" name="dilate" value="Dilate" onclick="return RecSelect(this.form,'rd')">

can u plz gimme solution for this now

nikkiH
08-22-2007, 07:46 PM
s is global, and being overwritten.

lettisha
08-25-2007, 06:49 AM
I've tried to declare s as local variable but then am not getting the alert message also. am getting the alert message only when s in global. is there any other solution for this??

glenngv
08-26-2007, 05:26 AM
Is this what you want?

function showAlert(chk){
if (chk.checked){
setTimeout(
function(){
alert(chk.value);
}
, 5000
);
}
}

<input type="checkbox" name="chk1" value="123" onclick="showAlert(this);" />
<input type="checkbox" name="chk2" value="456" onclick="showAlert(this);" />
<input type="checkbox" name="chk3" value="789" onclick="showAlert(this);" />
...

lettisha
08-28-2007, 09:46 AM
Thanku so muchl. yeah this is what i really wanted but i need to get the alert message only after clicking a submit button. but here in ur script message will be displayed on clicking the checkbox. as mine is a datagrid format am not able to do it. neways am trying for it.

glenngv
09-04-2007, 09:27 PM
But you didn't say anything about the submit button. You said the alert will show after the timer elapsed.



say suppose if am clicking on first record the timer starts and immediately if I click on another record before getting an alert message for previous checkbox then i need to get 2 alert messages for both the checkboxes separately.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum