Get fields value javascript sharepoint 2010

How can i get field values in a newform.aspx without the weird id.

Can I get by sharepoint internal field name or field name, or by title?

Ex.

<input name="ctl00$m$g_ac5e7c13_02a0_4407_9219_c5ed488b0821$ctl00$ctl05$ctl00$ctl00$ctl00$ctl04$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_m_g_ac5e7c13_02a0_4407_9219_c5ed488b0821_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_TextField" title="Morada Required Field" class="ms-long ms-spellcheck-true">

javascript to get value

var Morada = document.getElementById("ctl00_m_g_ac5e7c13_02a0_4407_9219_c5ed488b0821_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_TextField").value;

July 14th, 2014 10:44am

you can get the filed value like this

http://spjsblog.com/2010/05/28/get-or-set-value-for-sharepoint-field-in-newform-editform-and-dispform-get-only-in-dispform/

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2014 11:24am

Its simple using jquery

var Morada = $("input[title='Morada Required Field']").val()

July 14th, 2014 11:28am

Prasath's jQuery would work.

If you don't want to use jQuery, you can use the native JavaScript document.querySelector() or document.querySelectorAll(), using the same CSS selector syntax. Should run a bit faster than the jQuery equivalent.

var Morada = document.querySelector("input[title='Morada Required Field']").value;
CSS Selectors Reference: http://www.w3schools.com/cssref/css_selectors.asp
Free Windows Admin Tool Kit Click here and download it now
July 17th, 2014 6:00pm

Jason, this is THE BEST and easiest solution I have found to get the value in a single field from a Sharepoint list.  I have spent hours trying to do this.  Thank you so much!!!!!!  I wish I could vote 250 times.
  • Proposed as answer by toya0324 12 hours 13 minutes ago
March 21st, 2015 3:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics