• Resolved francinegg

    (@francinegg)


    After your kind help with this issue, I built multiple converter forms for a page on my website.

    As advised, I used scripts like the one below in HTML fields.

    <script>
    jQuery(document).on('keydown', '[id*="fieldname2_"]', function(){ editing='mm';});
    
    jQuery(document).on('keydown', '[id*="fieldname3_"]', function(){ editing='inch';});
    
    jQuery(document).on('keydown', '[id*="fieldname4_"]', function(){ editing='metre';});
    
    jQuery(document).on('keydown', '[id*="fieldname5_"]', function(){ editing='foot';});
    
    jQuery(document).on('keydown', '[id*="fieldname8_"]', function(){ editing='yard';});
    
    jQuery(document).on('keydown', '[id*="fieldname10_"]', function(){ editing='km';});
    
    jQuery(document).on('keydown', '[id*="fieldname11_"]', function(){ editing='mile';});
    </script> 

    In the back-end ‘preview’ they all work very well, and they work if placed on a page alone. But they don’t work if they’re on the same page, which I figure is because the “parameter”(?) for the jquery is too broad and is picking up all “fieldname4_[whatever]”.

    Is there a way I can focus it only on the form being used?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @francinegg,

    In this case, that you are inserting multiple forms in the same page, to prevent conflicts between the fields’ selectors in the code and the fields in the forms, I recommend you to assign different and unique class names to these fields (the class names are assigned to the field through their attributes: “Add CSS Layout Keywords”), and then, the block of code would be similar to:

    
    <script>
    jQuery(document).on('keydown', '.mm input', function(){ editing='mm';});
    jQuery(document).on('keydown', '.inch input', function(){ editing='inch';});
    jQuery(document).on('keydown', '.metre input', function(){ editing='metre';});
    jQuery(document).on('keydown', '.foot input', function(){ editing='foot';});
    jQuery(document).on('keydown', '.yard', function(){ editing='yard';});
    jQuery(document).on('keydown', '.km input', function(){ editing='km';});
    jQuery(document).on('keydown', '.mile input', function(){ editing='mile';});
    </script>
    

    I’ve assumed that the class names assigned to the fields were: mm, inch, metre, foot, yard, km and mile, respectively.

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Only direct script at specific form’ is closed to new replies.