0

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, "-"); }');
}
_spBodyOnLoadFunctionNames.push("SiteRequestInitNewform");

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

2
  • could you provide some example html? Commented Jan 8, 2015 at 11:24
  • Provided current code Commented Jan 8, 2015 at 13:07

1 Answer 1

0

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.

1
  • Okay, I guesse I'll just keep using the querySelectorAll for now. Thanks! Commented Jan 9, 2015 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.