I'm looking for an object that contains the form field ids or something similar.

Something similar to the _spPageContextInfo object for form fields.

Anyone have an idea?

EDIT: This code I'm using now is this:

function SiteRequestInitNewform() { 
    document.querySelectorAll('input[title="Title Required Field"]')[0].setAttribute('onblur', 'if (document.querySelectorAll(\'input[title="URL Name Required Field"]\')[0].value == ""){ document.querySelectorAll(\'input[title="URL Name Required Field"]\')[0].value = document.querySelectorAll(\'input[title="Title Required Field"]\')[0].value.replace(/[^a-zA-Z0-9]/g, "-"); }');

But I'd like to have a fixed ID to get the field, the title attribute changes to easily.

Not to mention that this function is not supported < ie8

  • could you provide some example html? – Mx. Jan 8 '15 at 11:24
  • Provided current code – Christoffel de Gruyter Jan 8 '15 at 13:07

As far as i know there is no object that contains all form field id's. You can access all form input's via something like document.forms["form_name"].getElementsByTagName("input"); and afterwards check the objects for your input.

When your problem is, that the id is prefixed (i.e. ctl00_ctl52_ShellNewsfeed) you could simply check if the id ends with the id (or simply set the ClientIdModeto static).

You could also use a similar selector like document.querySelectorAll('input[id=*"YourIdEndsWith"]') to get all elements which id's are ending with your input's id.

| improve this answer | |
  • Okay, I guesse I'll just keep using the querySelectorAll for now. Thanks! – Christoffel de Gruyter Jan 9 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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