简体   繁体   中英

copy select2 data to hidden field

I would like to find a way to copy the selected values of a select2 , to be copied to a hidden field (in order to be abel to process them later with ssjs) It works fine in csjs , at the click of a button :

<xp:button    value="Label"    id="button12">
            <xp:eventHandler event="onclick" submit="true"      refreshMode="partial" refreshId="computedField7">
                <xp:this.script><![CDATA[var test=  ("Selected value is: "+x$("#{id:vehicle}").select2("val"));
   var demo = XSP.getElementById("#{id:inputHidden1}");
   demo.value = test;
   alert (test);
  ]]></xp:this.script>

            </xp:eventHandler></xp:button>

But I've tried to do this with jquery , but it doesn't seem to work. I get the correct alert message , but my field doesn't update. I tried already a lot of ways /syntaxes to get a handle to this field ...

<script>
$("#vehicle").select2();
$(document.body).on("change","#vehicle",function(){
var thisone = $("#vehicle").select2("val");
$("#button12").trigger("click");
var demo = $(XSP.getElementById("#{id:inputHidden1}"));
$('#view:_id1:inputHidden1').val(thisone)
$('input[name="{id:inputHidden1}"]', '#vehicle').select2('val');
alert("Selected value is:"+ thisone);
});
</script>

To find an XPages field from a client side script, I usually use a selector that finds it by searching for fields where the id in the browser ends with the specified value.

So if your XPage field is named inputHidden1 , you can use $("input[id$='inputHidden1']")

Alternatively you can also use the x$ function: x$("#{id:inputHidden1}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM