1

I'm trying to pass value to the edit form on Edit button click (Anchor tag). When i'm alerting it it gives me undified in alert. When i'm alerting Charector value it shows proper result, but not for ID's.

here is my code:

<a href="javascript:void(0);" class="btn btn-info btn-sm item_edit" data-statusCode="'+data[i].statusCode+'" data-status="'+data[i].status+'">Edit</a>

data[i].status in alert gives me Status value, but data[i].statusCode gives Undified. As in Image I'm getting values in response.

enter image description here

My Edit code:

//get data for update record
    $('#showList').on('click','.item_edit',function(){
        var statusId = $(this).data('statusCode');
        var status = $(this).data('status');

        $('#Modal_Edit').modal('show');
        alert(statusId);
        $('[name="statusId_edit"]').val(statusId);
        $('[name="status_edit"]').val(status);

    });

Any kind of help is welcome, thanks in advance.

1
  • You need to get text() of that .item_edit instead of data. Commented Mar 18, 2019 at 7:30

1 Answer 1

2

The issue is with camel case in your data-statusCode attribute.

Change data-statusCode="'+data[i].statusCode+'"

to data-status-code="'+data[i].statusCode+'"

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, its working. Will you please explain difference between data-status-code and data-statusCode as my value stored in statusCode and not in status-code.
data-status-code is only for the html. You can keep the JS value in data.statusCode but .data() function expects - separated values and converts them to camel case automatically.

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.