Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fastest way to retrieve checked fields
Message
 
 
À
06/08/2001 10:18:34
Information générale
Forum:
Internet
Catégorie:
Javascript
Divers
Thread ID:
00538718
Message ID:
00541135
Vues:
29
Hi!

This could work ok if you have no other items on form with name like 'XXXXXXX{number}'. More quick way will be only, as I mentioned, if you put all checkboxes itno separate form where no other controls exist, or name all checkboxes with the same name when ID is like 'MessageXXX' or vise versa. This way you will be able to access to each checkbox as to the array, so no scan of ALL controls, just checkboxes. I don't know if following will work (do not remember if reference theForm.CHECKMARKS is correct), but you can try it (I assumed you used ID 'CHECKMARKS' for all checkboxes and name like 'MessageXXX':
function MessageMark(theForm)
{
   lcField=""
   lcMessageMark=""
   for (i = 0; i < theForm.CHECKMARKS.length; i++)
      {
      if (theForm.CHECKMARKS[i].checked==true)
        {
          lcField=theForm.CHECKMARKS[i].name
          lcMessageMark=lcMessageMark+lcField.substring(7,13)+","
        }
      }
    if (lcMessageMark.length>0)
      return lcMessageMark.substring(0,lcMessageMark.length-1)
    else
      return ""
}
>>Well, I wondered because checkbox values could be catched at the server side in the ASP scripts. Anyway, if you want that in such form, loop through all controls of the form. Array in Java Script have count property. In the loop check if control's name start from 'Message', if yes, get checked status and put into result string the name, if required.
>
>The reason to do it at the page level is because that page is not firing anything at the server but it is updating a value from another page.
>
>This is what I came up with:
>
>
>function MessageMark(theForm)
>{
>   lcField=""
>   lcValue=""
>   lcMessageMark=""
>   for (i = 0; i < theForm.length; i++)
>      {
>      lcField=theForm.elements[i].name
>      lcValue=lcField.substring(7,13)
>      floatValue=parseFloat(lcValue)
>      if (!isNaN(floatValue))
>         {
>         if (theForm.elements[i].checked==true)
>            {
>            lcMessageMark=lcMessageMark+lcValue+","
>            }
>         }
>      }
>   if (lcMessageMark.length>0)
>      {
>      lcMessageMark=lcMessageMark.substring(0,lcMessageMark.length-1)
>      }
>   return lcMessageMark
>}
>
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform