javascript validation for dynamically generated fo

Results 1 to 3 of 3

Thread: javascript validation for dynamically generated fo

  1. #1
    viky Guest

    Default javascript validation for dynamically generated fo

    hello,<BR>friends<BR>i am confused because of one thing in mine project.<BR>i made a file which has dynamically generated form.<BR>i will have a any no of radio buttons as per the user&#039s wish.<BR>now here comes the problem<BR>i also want the client side validation that user has clicked <BR>checeked all that no of radio button he has entered .<BR>there is also one-one input type attached with the radio button<BR>i also want that if he has entered that content properly or not.<BR>so <BR>i tried mine best and last i leave this thing<BR>on u beautiful people,<BR>i am waiting for the answer from your side.<BR>thnaks<BR>-viky

  2. #2
    Join Date
    Dec 1969

    Default RE: javascript validation for dynamically generate

    give the same name (say radio1)for the radio buttons while generating dynamically.<BR>so when u give the same name to all u can refer them as radio1[0],radio1[1]......<BR><BR>then in the form&#039s onSubmit event call a javascript function as<BR><BR>&#060;SCRIPT LANGUAGE=javascript&#062;<BR>function test()<BR>{<BR>for (i=0;i&#060;=1;i++)<BR>{<BR>if(document.form1.rd1[i].checked==true)<BR>{<BR>alert("radio button" + i + "checked:");<BR>}<BR>else<BR>{<BR>alert("radio button" + i + "unchecked:");<BR>}<BR>}<BR>}<BR><BR>&#060;/SCRIPT&#062; <BR><BR>same as for text boxes.

  3. #3
    Join Date
    Dec 1969

    Default RE: javascript validation for dynamically generate

    This a bit involved, but....<BR><BR>If there are a lot of possible variations, I would think of doing this on the server side. This means the form has to be submitted to the server before it can be validated, but you can build a robust set of procedures to deal with the variations. (Of course it also means you&#039ll have to recreate the form, w/ something indicating which items the user must correct.)<BR><BR>However, best practice suggest that you try for the client side approach. This way you don&#039t waste a round trip to the server for validation. Now, if the list of possible form items is small enough you could address them by name, verify that they exist and then validate.<BR><BR>if ( document.forms(strFormName).item(strItemName)!= undefined )<BR>{<BR>//here you&#039d have validation code<BR>} <BR><BR>I would try grouping your form items together based on the type of validation they require. Then write the functions to deal w/ them on a group basis. You can then have a list (2 arrays) of possible form items and the function used to validate that type of form item. Your validation code would run thru the list, figure out if the form item is present on the page, and if it is, validate.<BR><BR>You can also address the form items by index numbers, if I&#039m not mistaken. But, I don&#039t know how you&#039d determine what time of validation each form item requires. <BR><BR>Or, you could have a little libary of functions to validate each form item, and then include those function in the output based on what form items are being used in that particular page.<BR><BR>Some ideas...<BR>

Posting Permissions

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