New to Sharepoint 2010, but not new to coding.
I have created a custom list with 4 text input fields and I am trying to target one of the fields called SUID with custom Javascript to modify how the input field behaves. The field is to capture numbers from an ID scanner that acts as a keyboard input, but it displays some unnecessary numbers.
When I go onto my allItems.aspx, click the green plus sign, and inspect the input field for SUID, I get this HTML code:
<input name="ctl00$m$g_0842343c_4653_49c3_b9ec_28682a09dff0$ff01$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_m_g_0842343c_4653_49c3_b9ec_28682a09dff0_ff01_ctl00_ctl00_TextField" title="SUID" class="ms-input ms-spellcheck-true">
I want to add some Javascript code so I can change what is inputted into that field so it slices and gets the exact amount of numbers I need.
For instance, this is what the ID scanner outputs: ;708089113=0184?
I am only looking for the 708089113, so I have coded some Javascript to remove the semi-colon (;), and everything from the equal sign (=) and on:
<script type="text/javascript">
var elm = document.getElementById('ctl00_m_g_0842343c_4653_49c3_b9ec_28682a09dff0_ff01_ctl00_ctl00_TextField');
elm.addEventListener('change', function (e) {
var s = this.value, i = s.indexOf('=');
if (i !== -1) {
s = s.slice(1, i);
this.value = s;
}
});
</script>
I have tried injecting it into allItems.aspx underneath
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
But I have a feeling that I'm not targeting the right ID. Is there a way to figure out what the ID of this field is? Or is there another method I could try to target this input field? Is it possible I'm not injecting the code in the right area?

0 commentaires:
Enregistrer un commentaire