Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2007
    Location
    Andhra Pradesh, India
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    display an alert messages recursively by clicking a checkbox

    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.....

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • Users who have thanked nikkiH for this post:

    lettisha (08-22-2007)

  • #3
    New Coder
    Join Date
    Jun 2007
    Location
    Andhra Pradesh, India
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    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

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    s is global, and being overwritten.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Jun 2007
    Location
    Andhra Pradesh, India
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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??

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Is this what you want?
    Code:
    function showAlert(chk){
      if (chk.checked){
        setTimeout(
          function(){
            alert(chk.value);
          }
          , 5000
        );
      }
    }
    Code:
    <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);" />
    ...

  • #7
    New Coder
    Join Date
    Jun 2007
    Location
    Andhra Pradesh, India
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    But you didn't say anything about the submit button. You said the alert will show after the timer elapsed.

    Quote Originally Posted by lettisha
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •