0
  • i have a form with many controls(drop down list, check box, radio button ...).
  • my form created dynamically and each form has different controls.
  • some of controls must call function,
  • my function must declare which control called it.

what can i do?
how name controls?
how manage which controls call or which of them not?
how my function know which control called it?

many thanks.

ps: i don't want to use server side controls, i use just client site controls.

2
  • the function to be called is same one? Commented Sep 29, 2013 at 19:03
  • thank you. yes. in fact some control must present himself to a function, and function alert which control selected, change or ... Commented Sep 29, 2013 at 19:41

1 Answer 1

0

Assuming you're using jQuery, adding controls dynamically to a <div class="controls"> .

Then you can do something like:

$(".controls").on("click", your_function);

In your_function:

function your_function(target){
    //target would be the control which fires `click` event
    //you can assign them different custom attributes
    //like <input mid="123" type="text" />
    //then get this custom attribute(mid)
    var identifier = $(target).attr("mid");
    //distinguish them by different identifier
}

Furthermore, if it involves select or file control, you should bind change event as well to make it more compatible.

3
  • thank you, it works. but in vs2010, when i put mid attribute i get this message: VALIDATION (XHTML 1.0 TRANSITIONAL):ATTRIBUTE 'MID' IS NOT A VALID ATTRIBUTE OF ELEMENT 'DIV'. is it correct to use this attribute? is it under seo or other standards? what do you think of using name instead of costume attribute Commented Sep 30, 2013 at 3:24
  • i found new attribute in html5 : data-*, what do you think of this? (w3schools.com/tags/ref_standardattributes.asp) Commented Sep 30, 2013 at 3:32
  • @MohammadAdibi yeah sure, data-* is better choice for html5 compatible html Commented Sep 30, 2013 at 7:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.