Ad
Track Which Dynamic Anchor Tag Was Submitted In Javascript
I don't have much experience with JavaScript.
If User has already pressed on this dynamic anchor tag, I want the that it alerts him with a different type of confirm message.
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Dataset</th>
</tr>
</thead>
<tbody>
@foreach ($dumpDb as $key => $value)
<tr>
<td scope="row">{{ $value->dataset }}
<span>
<a class="downloadLink" target="_blank" rel="nofollow noreferrer" href="{{Route('dump.downloadFile', ['id' => $value->dataset ])}}" onclick="return ConfirmDownload()"> Download </a>
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
<script type="text/javascript">
// dalifyDownloads - how many times a user can download file in 24hours. By default 5 files per day.
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (User has already pressed on this button) {
var x = confirm("Are you sure you want to download this file?");
if (x)
return true;
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}
</script>
Ad
Answer
You can keep track using a variable outside the function:
var pressed = false;
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (!pressed) {
var x = confirm("Are you sure you want to download this file?");
if (x){
pressed = true;
return true;
}
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad