1

I have created a javascript function, and I've put in the html code javascipt, but when I make a branching using if else there is an error with the statement "SyntaxError: missing) after argument list" on the sidelines "if" is. following my javascript code.

function tabelListPegawai(data){
    return baris = $('<tr>\
            <td>'+data.nik+'</td>\
            <td>'+data.nama_pegawai+'</td>\
            <td>'+data.nama+'</td>\
            <td>'+data.nama_jabatan+'</td>\
            <td>'if(data.status == 1){'Karyawan Tetap'}else if(data.status == 2){'Karyawan Tidak Tetap'}'</td>\
            <td style="text-align: center;">\
            <a class="btn btn-small aksi_atas" rel="tooltip" title="Ubah" onclick="editPegawai('+data.id_pegawai+')"><i class="icon-edit"></i></a>\
            <a class="btn btn-small aksi_atas" rel="tooltip" title="Hapus" onclick="hapusPegawai('+data.id_pegawai+', '+data.nik+')"><i class="icon-remove"></i></a>\
            </td>\
    </tr>'); 
}

Can you help me. thank you

1
  • 1
    You can't interpolate if..else like that but you can use a ternary operator. Also I'd recommend concatenating your string properly with + for best support across browsers. Commented Jan 6, 2013 at 4:33

1 Answer 1

1

If the switch is only 1 or 2 then this would work

 <td>' + (data.status == 1?  'Karyawan Tetap' : 'Karyawan Tidak Tetap') + '</td>\

Or you could do this

 var baris = $('<tr>\
  ...
 <td>';
 if(data.status == 1) baris+='Karyawan Tetap';
 else if(data.status == 2) baris+='Karyawan Tidak Tetap';
 baris+=' <td style="text-align: center;">\
 ....
Sign up to request clarification or add additional context in comments.

Comments

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.