通过javascript捕获对字段所做的更改

时间:2013-05-23 07:01:16

标签: jquery

以下是我所面临问题的背景。

我有Visualforce页面(Salesforce),它有一个查找字段。

查找字段是一组隐藏字段,一个普通输入字段和一个带有href的图像,它打开一个弹出窗口供用户选择。每个选定的值都有2个值

  1. selectedvalue的名称
  2. 所选值的ID。
  3. 名称存储在非隐藏输入字段中,并存储在以lkid结尾的隐藏字段中。 Html看起来像这样

        <div id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:optableAccount" style="position:relative">
    //Below hidden field stores the id
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid" type="hidden" value="001i0000008OJ9R" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid">
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkold" type="hidden" value="Abbott Insurance" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkold">
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lktp" type="hidden" value="001" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lktp">
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspf" type="hidden" value="0" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspf">
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspfsub" type="hidden" value="0" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspfsub">
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod" type="hidden" value="1" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod">
    <span class="lookupInput"> // Below input stores the name
    <input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup" class="accClass" type="text" size="20" onchange="getElementByIdCS('leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid').value='';getElementByIdCS('leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod').value='1';" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup" maxlength="255" style="opacity: 0.1; width: 250px;">
    <script>
    <a id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkwgt" class="accClass" title="Account Name Lookup (New Window)" onclick="setLastMousePosition(event)" href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3DleadConversionPage%253AleadConversionForm%26lknm%3DleadConversionPage%253AleadConversionForm%253ApBConvertLead%253ApbSectionLeadSection%253ApbsiAccountName%253AaccountLookup%26lktp%3D%27%20%2B%20getElementByIdCS%28%27leadConversionPage%3AleadConversionForm%3ApBConvertLead%3ApbSectionLeadSection%3ApbsiAccountName%3AaccountLookup_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27leadConversionPage%3AleadConversionForm%3ApBConvertLead%3ApbSectionLeadSection%3ApbsiAccountName%3AaccountLookup%27%29.value.substring%280%2C%2080%29%29%29">
    </span>
    <select id="someList" class="accSelectandlookup" >
    </div>
    

    每当名称更改时,ID也会更改。当名称改变时,我需要捕获id并将它们添加到选择

    查找的名称和ID是accountLookup,以获取名称,我可以搜索以accountLookup结尾的所有输入。我可以在我的表单中进行多次查找,但我只需要此查找的名称和ID,其名称/ id中的accountLookup将附加在select中。

    这是我在SO的一些伟大人物的帮助下到目前为止所做的jquery。 我面临的问题是我没有得到id值。它的空白

     $('input[id*="accountLookup"]').change(function() {
            var accid ='';
            //Loop through all the textboxes and find the one  with lkid
            $.each(['up_lkid'], function(i,element) {
                    accid = getInputValue(element); // Get the value of the inputbox ending with lkid
                    alert('llllll' + accid);
            });                
            var accname= $(this).val();
    
            //Get the closest div and find for an elemnet which has class of accSelectLookup
            var selects = $(this).closest('div').find('.accSelectandlookup') ;
    
           //Check if the accid is already present in the selectoptions and if not then add  
           if (!selects.find('option[value="' + accid + '"]').length) {
            selects.append('<option value="' + accid + '">Attach to Existing : ' + accname + '</option>');
            }
    
        });
        function getInputValue(endWith) {
             return $('input[id$="' + endWith + '"]').val();   
            }
    
      });
    

0 个答案:

没有答案