The code of a href link that comes dynamically from database
@foreach($doctor->tuesday as $tuesday)
<a class="timing" id="{{$tuesday->id}}" onclick="clicktime({{$tuesday->id}})" href="{{url('/')}}/fixschedule/{{$tuesday->id}}">
<span>{{date("g:i a",strtotime($tuesday->starttime))}}</span>
</a>
@endforeach
after select class name will be change to timing selected for blue highlight,
i want to select an a element like this
when i will press the button then the i want to redirect the specified link of a href and i want to select only one element at a time
code of button
<div class="submit-section proceed-btn text-right">
<a href="#" onclick="submit()" class="btn btn-primary submit-btn">Proceed to Pay</a>
</div>
i used here code of jquery that only one element can change now i want to go only redirected link after submit pressed
<script>
function clicktime(id)
{
$("a").removeClass("timing selected");
$("a").toggleClass("timing");
document.getElementById(id).className = "timing selected";
}
</script>
First, prevent the a tag from redirecting with preventDefault();
@foreach($doctor->tuesday as $tuesday)
<a class="timing" id="{{$tuesday->id}}" onclick="preventDefault();clicktime({{$tuesday->id}})"
href="{{url('/')}}/fixschedule/{{$tuesday->id}}">
<span>{{date("g:i a",strtotime($tuesday->starttime))}}</span>
</a>
@endforeach
then set the url on code of button like
<script>
function clicktime(id)
{
$("a").removeClass("timing selected");
$("a").toggleClass("timing");
document.getElementById(id).className = "timing selected";
$(".submit-btn").attr('href',$("#"+id).attr('href');
}
</script>