none
Get fields value javascript sharepoint 2010 RRS feed

  • Question

  • 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;

    Monday, July 14, 2014 10:44 AM

Answers

  • Its simple using jquery

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


    --Cheers

    • Marked as answer by JasonGuo Sunday, July 27, 2014 12:58 PM
    Monday, July 14, 2014 11:28 AM
  • 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
    • Edited by thriggle Thursday, July 17, 2014 6:00 PM
    • Marked as answer by JasonGuo Sunday, July 27, 2014 12:58 PM
    Thursday, July 17, 2014 6:00 PM

All replies

  • 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/

    Monday, July 14, 2014 11:24 AM
  • Its simple using jquery

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


    --Cheers

    • Marked as answer by JasonGuo Sunday, July 27, 2014 12:58 PM
    Monday, July 14, 2014 11:28 AM
  • 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
    • Edited by thriggle Thursday, July 17, 2014 6:00 PM
    • Marked as answer by JasonGuo Sunday, July 27, 2014 12:58 PM
    Thursday, July 17, 2014 6:00 PM
  • 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 Saturday, March 21, 2015 7:17 PM
    Saturday, March 21, 2015 7:17 PM