-2

I am not able to create an edit in place feature with JavaScript/ jQuery. I could not use the plugin editinplace, because I need to put a datepicker on it. My code below does not work for some strange reason:

function editImpfDatumImpfung1Clicked(sender)
{
    var sText = $(this).text();
    var sId = $(this).attr("id");
    $(this).attr("id", "tobechanged");
    $(this).after('<input type="text" id="' + sId + '" value="' + sText + '" />');
    $(this).remove();
    bImpfung1Clicked = true;
    $("#" + sId).focus();
    $("#" + sId).datepicker(datepickerOptions);

    if (bFirstRegisterImpfung1 === true)
    {
        firstRegisterImpfung1();
        bFirstRegisterImpfung1 = false;
    }
}

$(document).ready(function()
{
    $elem = $("span[id^='impfung_1['");

    if ($elem.length > 0)
    {
        bFirstRegisterImpfung1 = true;
        $elem.click(editImpfDatumImpfung1Clicked);
    }
});

Edit:

No Errors in console.

console.log($("#" + sId).val()); causes undefined

Edit 2: Just needed to escape the id like this:

sId = sId.replace(/[[]/g,'\\[');
sId = "#" + sId.replace(/]/g,'\\]');

Thanks for your advice.

alpham8
  • 1,314
  • 2
  • 14
  • 32

1 Answers1

1

I imagine you have a typo in the following line:

$elem = $("span[id^='impfung_1['");

try this instead:

$elem = $("span[id^='impfung_1']");
Grzegorz Pawlik
  • 2,198
  • 1
  • 18
  • 18