469,331 Members | 1,479 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

Check box Alert if only One check Box

nitindel
Hi All,
I am working on ASP , VBScript and Javascript.
I am making a grid in ASP VBScript..and eneter checkboxes in one column......

The problem is that if there is one record in the grid it is showing as :

Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

Below is the javascript code that i am using on Button click

[code]:
function Edit()
{
var ctr=0;
for (i=0;i<document.managecontribution.checkmanage.len gth;++i )
{
if (document.managecontribution.checkmanage[i].checked)
{
ctr=ctr+1;

}

}

[code]


Also i am using the Html "Submit" type not the "button" type


Thanks in Advance
Feb 21 '08 #1
14 3680
Hi All,
I am working on ASP , VBScript and Javascript.
I am making a grid in ASP VBScript..and eneter checkboxes in one column......

The problem is that if there is one record in the grid it is showing as :

Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

Below is the javascript code that i am using on Button click

Expand|Select|Wrap|Line Numbers
  1. :
  2. function Edit()
  3. {
  4. var ctr=0;
  5. for (i=0;i<document.managecontribution.checkmanage.length;++i )
  6. {
  7. if (document.managecontribution.checkmanage[i].checked)
  8. {
  9. ctr=ctr+1;
  10.  
  11. }
  12.  
  13. }
  14.  
  15.  

Also i am using the Html "Submit" type not the "button" type


Thanks in Advance
Feb 21 '08 #2
hsriat
1,654 Expert 1GB
Hi All,
I am working on ASP , VBScript and Javascript.
I am making a grid in ASP VBScript..and eneter checkboxes in one column......

The problem is that if there is one record in the grid it is showing as :

Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

Below is the javascript code that i am using on Button click

Expand|Select|Wrap|Line Numbers
  1. :
  2. function Edit()
  3. {
  4. var ctr=0;
  5. for (i=0;i<document.managecontribution.checkmanage.length;++i )
  6. {
  7. if (document.managecontribution.checkmanage[i].checked)
  8. {
  9. ctr=ctr+1;
  10.  
  11. }
  12.  
  13. }
  14.  
  15.  

Also i am using the Html "Submit" type not the "button" type


Thanks in Advance

What are you doing to ctr afterwards?
is it this....
Expand|Select|Wrap|Line Numbers
  1. if (!ctr) alert('Please select the record to edit or delete');
Feb 21 '08 #3
hsriat
1,654 Expert 1GB
You won't get any better answers by repeating the question..
Feb 21 '08 #4
No...
i am doing like this:-



if (ctr<=0)
{
alert('Please Check the story to edit');
return false;
}
else if (ctr>1)
{
alert('Please Check only one story to edit');
return false;
}
Feb 21 '08 #5
hsriat
1,654 Expert 1GB
No...
i am doing like this:-



if (ctr<=0)
{
alert('Please Check the story to edit');
return false;
}
else if (ctr>1)
{
alert('Please Check only one story to edit');
return false;
}
What about if (ctr == 1)?
use else instead of else if (ctr>1)...
Feb 21 '08 #6
in the else part i am redirecting to another page like this:

else
{
document.managecontribution.action = "addcontribution.asp?action=Edit";

}
Feb 21 '08 #7
hsriat
1,654 Expert 1GB
in the else part i am redirecting to another page like this:

else
{
document.managecontribution.action = "addcontribution.asp?action=Edit";

}
oh! I'm sorry.. i didn't read the last line...

But, where's the problem....?
Paste the full code... may be then I cud find the solution..
Feb 21 '08 #8
acoder
16,027 Expert Mod 8TB
You won't get any better answers by repeating the question..
Too right. Merged the threads. nitindel, please don't double post your questions.
Feb 21 '08 #9
Hi ...
Here is the Full Javascript code.......

Expand|Select|Wrap|Line Numbers
  1. function Edit()
  2. {
  3.     var ctr=0;
  4.  
  5.     for (i=0;i<document.managecontribution.checkmanage.length;++i)
  6.     {
  7.         if(document.managecontribution.checkmanage[i].checked)
  8.        {
  9.             ctr=ctr+1;
  10.                    }
  11.  
  12.     }
  13.         if (ctr<=0)
  14.     {
  15.         alert('Please Check the story to edit');
  16.         return false;
  17.     }
  18.     else if (ctr>1)
  19.     {
  20.         alert('Please Check only one story to edit');
  21.         return false;
  22.     }
  23.     else 
  24.     {
  25.     document.managecontribution.action = "addcontribution.asp?action=Edit";
  26.  
  27.  
  28.     }    
  29.  
  30. }




and it is called as :

<input name="submit" type="submit" class="buttons" onclick="javascript:return Edit()" value="Edit" />



I once again repeat the problem.....

I make the grid Dynamicaally in ASP using VBScript.......

and then clicking on the checkbox and then ob edit button redirects to another page with that corresponding record details ......

i have an alert that please select one story at a time.....

and a required alert as that "Please select the Story to Edit"


Now if i have more than one record in the grid...it is working fine....

But when only one row is populated...in the grid...it throws error...
"Please select the story to Edit" even if i have selected the checkbox(Story) to edit.....

Please let me know what possible error can it be...

Tonite i have to complete this module......
Thanks a lotttttttttttttttttttttttt in advance....
Feb 21 '08 #10
hsriat
1,654 Expert 1GB
BTW, why are you using Checkbox if you have to allow user to select one of the stories at a time?..
Use radio buttons...
Expand|Select|Wrap|Line Numbers
  1. function Edit()
  2. {
  3.     var ctr=0;
  4.  
  5.     for (i=0;i<document.managecontribution.checkmanage.length;++i) {
  6.         if(document.managecontribution.checkmanage[i].checked) {
  7.             ctr++;
  8.         }
  9.     }
  10.     if (ctr<=0) {
  11.         alert('Please Check the story to edit');
  12.         return false;
  13.     }
  14.     else if (ctr>1) {
  15.         alert('Please Check only one story to edit');
  16.         return false;
  17.     }
  18.     else {
  19.         document.managecontribution.action = "addcontribution.asp?action=Edit";
  20.         return true;
  21.     }
  22. }
Feb 21 '08 #11
I am using Check box because i have a delete option also...which can select multiple records and delete them at one GO.......
Feb 21 '08 #12
hsriat
1,654 Expert 1GB
I am using Check box because i have a delete option also...which can select multiple records and delete them at one GO.......
tell me... is the code working?
Feb 21 '08 #13
Yup..........!!!!!!!!!
Feb 21 '08 #14
acoder
16,027 Expert Mod 8TB
nitindel, the proper way to use code tags is as follows:

[CODE=javascript]
Your JavaScript code here
[/code]

PS. glad to see that you've got it working.
Feb 22 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Steve Wylie | last post: by
2 posts views Thread by Roger Withnell | last post: by
3 posts views Thread by NH | last post: by
18 posts views Thread by staeri | last post: by
2 posts views Thread by V_S_H_Satish | last post: by
9 posts views Thread by morellik | last post: by
11 posts views Thread by -Lost | last post: by
14 posts views Thread by Cylix | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.