0

I currently have a list form that I am included custom fields on. I'm using jquery to store the values.

To store the values I've create a function that will be called when the Save button is clicked. The issue I'm having is when I debug the code in the browser it gets the SubmitForm function and the values are stored to hidden single line of text fields (out of the box sharepoint fields).

When I open the item in display or Edit the single line of text fields never retain the value.

What can I do to make sure the field hold the value and the form is saved?

SubmitForm function

SubmitForm = function() {
var resVal = $('input:radio[name="EventSet"]:checked').val();
var resCat = $('.Category option:selected').val()
        if (resVal != undefined)
        {
            $('input[title="ResField"]').val(resVal)
        }

       $('input[title="ReservationCategory2"]').val(resCat)
}

Onclick Event

$('body').on('click', 'input[value="Save"]', function() {
   SubmitForm();
}
  • What you mean by field dont hold value? Can you post a screenshot? – Amal Hashim Apr 30 '15 at 20:39
  • Also I believe you are using wrong variables reseVal vs resVal? – Amal Hashim Apr 30 '15 at 20:49
  • @AmalHashim What I'm trying to do is store the value from the custom input into a single line of text field ResField and ReservationCategory2 SharePoint . When I click save it should set the values to the single line of text fields, but when I look in edit or display the fields remain blank and don't have the value. Also the variable up here is type on my part. – zingwing Apr 30 '15 at 22:09
1

You should change your approach. Instead of setting value on Save Click, try setting on change events

$('input:radio[name="EventSet"]').click(function(){
    var resVal = $('input:radio[name="EventSet"]:checked').val();
    if (resVal != undefined)
    {
        $('input[title="ResField"]').val(resVal)
    }

    alert(resVal);
    alert($('input[title="ResField"]').val());
});

$('.Category').on('change', function (e) {
    var resCat = $('.Category option:selected').val()
    $('input[title="ReservationCategory2"]').val(resCat)

    alert(resCat);
    alert($('input[title="ReservationCategory2"]').val());
});
0

You should be using fields, either HTML or ASP to post them if you're going to use the submit method, which then submits the contents of the form. If you want them to look or behave when used a certain way, you can still use jQuery, but use it in conjunction (ie write to a form that is hidden behind the scenes)

If you're going to handle the data in jQuery/JavaScript alone, you're going to have to submit the data through a service call yourself (ex: REST) and then update the form accordingly to indicate the outcome.

  • Would I still need to do this if I was store the values to their own single line of text field (out of the box sharepoint text field)? – zingwing May 1 '15 at 13:06
  • If you store the values in a text field of any sort inside the form element then the submit form method should work for you to be able to access them. Same for ASP.NET. Just remember you can't access JS variables unless they're stored in an element that is passed as part of the form or passed to a service. – Graham May 1 '15 at 22:40

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.