Pass a parameter in javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Pass a parameter in javascript

Hello everyone.I have defined a function in js and I'm trying to pass a parameter to it in the click event of an img tag: <img onclick="RemovePic(@item.PicID)" src="~/Images/Galleries/@item.AcarModel.ModelName/@item.PicAddress" class="Image-Show" /> And the defintion of my function is: function RemovePic(id){} But my function doesnt get the parameter and id is always null

10th Sep 2020, 10:19 AM
maryam mirzapoor
maryam mirzapoor - avatar
8 Answers
0
maryam mirzapoor your function name is "deletePic" and you write "RemovePic" on the img tag this is the reason!
10th Sep 2020, 10:33 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
Oh no its ok I wrote it right in my code and the function works but id is null
10th Sep 2020, 10:42 AM
maryam mirzapoor
maryam mirzapoor - avatar
0
maryam mirzapoor then please send me your code, maybe bug some wherebinside your function!
10th Sep 2020, 10:46 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
Allright thx I will send it
10th Sep 2020, 10:49 AM
maryam mirzapoor
maryam mirzapoor - avatar
0
Also, make sure you set the img tag a corresponse ID!
10th Sep 2020, 10:53 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
What you mean?
10th Sep 2020, 11:00 AM
maryam mirzapoor
maryam mirzapoor - avatar
0
It's some thing like this: <img id="ID" onclick="removePic(ID)" src="" >
10th Sep 2020, 11:10 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
Well I didnt set id at all but I have another element like this and it works
10th Sep 2020, 12:01 PM
maryam mirzapoor
maryam mirzapoor - avatar