I want a particular link to be clicked when i select a specific option in dropdown list
i've tried
$('#OTST').change(function () {
if ($('#OTST').val() == "2")
{
$("#STSelectedPhase0").trigger('click');
}
else if ($('#OTST').val() == "3")
{
$("#OTSelectedPhase0").trigger('click');
}
else
{
$("#AllSelectedPhase0").trigger('click');
}
});
also tried
$("#AllSelectedPhase0").click();
but none of this worked
here is my code for links
@Html.EncodedActionLink("All", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = "" }, new { Id = "AllSelectedPhase0" });
@Html.EncodedActionLink("ST", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = 2 }, new { Id = "STSelectedPhase0" });
@Html.EncodedActionLink("OT", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = 3 }, new { Id = "OTSelectedPhase0" });
and the code for dropdown is :
<select id = "OTST" class = "form-control js-select " name="OTST" >
<option value="0" selected="selected">All</option>
<option value="2">ST</option>
<option value="3">OT</option>
</select>
Here is issue with you are trigger event click but actually it return your element. when you see $("#STSelectedPhase0").trigger('click')
or $("#STSelectedPhase0").click()
both returns your element `.
for auto click hyperlink you should use $("#STSelectedPhase0")[0].click()
$("#btngoogle").click(function(){ $("#alink")[0].click() });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a id="alink" href="https://www.google.com">Test</a> <input id="btngoogle" type="button" value="Google">
href
.
let me know if require more information. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.