html - Annoying behaviour in JavaScript function -


In the web page I have 2 different galleries with many images. Each button was given a button in order to be removed. I decided to use the same JavaScript function with a parameter to differentiate both galleries. These galleries are:

  & lt; Div class = "column col_12 gallery" & gt; In {% Testrigimages%} & lt; Div id = "testRigImage _ {{testrigimage.id}}" class = "image" align = "center" & gt; & Lt; A href = "{{MEDIA_URL}} {{testrigimage.image}}" & gt; & Lt; Img src = "{{MEDIA_URL}} {{testrigimage.image}}" width = "150" height = "100" /> & Lt; / A & gt; & Lt; I id = "deleteTestRigImage _ {{testrigimage.id}}" class = "icon-remove-mark mark-big" style = "display: none; cursor: indicator; color: dark gray; position: absolute; top: 9px; Left: 129px; "onclick =" javascript: deleteFile ('{{testrigimage.id}}', '0'); " & Gt; & Lt; / I & gt; & Lt; Br> {{Testrigimage.name}} & lt; / Div & gt; {% Empty%} no pictures have been added. {% Endfor%} & lt; / Div & gt; & Lt; Div class = "column coll_1 2 gallery" & gt; {%} For pictures in pictures & lt; Div id = "picture_ {{picture.id}}" square = "picture" align = "center" & gt; & Lt; A href = "{{MEDIA_URL}} {{picture.image}}" & gt; & Lt; Img src = "{{MEDIA_URL}} {{picture.image}}" width = "150" height = "100" /> & Lt; / A & gt; & Lt; I id = "deletePicture _ {{picture.id}}" class = "mark-remove-mark mark-big" style = "display: none; cursor: indicator; color: dark gray; position: full; top: 9px; Left: 129px; "onclick =" javascript: deleteFile ('{{picture.id}}', '1'); " & Gt; & Lt; / I & gt; & Lt; Br> {{Picture.name}} & lt; / Div & gt; {% Empty%} no picture has been added. {% Endfor%} & lt; / Div & gt;  

As you can see, both galleries are the same. The only difference is in the "onclick" attribute of the element, in order to pass both the "passfile" function to the "parameter" or "1" in addition to the difference. This is the "deleteFile" function:

  function deleteFile (model_id, type) {var x = Confirm ('You are about to delete this image. Are you certain?') If ( Type = "0") {alert (type) url = "/ tests / testSetUp / testrig /" + model_id + "/ delete /"} other {alerts (type) url = "/ tests / testSetUp / pictures /" + model_id "{{Cssrf_token}} ', data type:' text ', success: function (data, Textstats, requests) {data = EVEL ("(" + + + data + "); if (data. Success) {var n = noty ({text: 'image successfully removed Type: 'Success', Timeout: 750, Callback: {Close off: function () {location.reload ()}}})}} Else {var n = noty ({text:' Error. Please, contact the administrator. ', Type:' error ', timeout: 3000});}}}); }}  

And the problem is that always print (warning) "0"! When I click on the image of the first gallery (one with the "0" parameter), it alerts. When I click on an image of the second gallery, even if "1" is assigned, it also warns "0".

Why this behavior ??

See this code in your code if (type = "0") .

It should be to check equality (type == "0") or if (type === "0") .

Using a = will specify the value and evaluate the value specified, while == or === will compare two values.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -