you must add the value of your textbox in your condition like this :
$(document).ready(function() {
if (window.location.href.indexOf("mypage.aspx") > -1 && $('#myTextbox').val() == 'Text to match' ){
$('#myButoon').hide();
}
});
Question
I need to hide a button on a certain page if a text box has any value.
So far I can it from a specific page using this:
$(document).ready(function() {
if (window.location.href.indexOf("mypage.aspx") > -1 {
$('#myButoon').hide();
}
});
But for the button to be hidden I need to the user to be the specific page (mypage.aspx
) and for the text box to have any value (#myTextBox
).
La solution
you must add the value of your textbox in your condition like this :
$(document).ready(function() {
if (window.location.href.indexOf("mypage.aspx") > -1 && $('#myTextbox').val() == 'Text to match' ){
$('#myButoon').hide();
}
});
Autres conseils
This should do what you want:
$(document).ready(function() {
if (window.location.href.indexOf("mypage.aspx") > -1) {
// if a button is pressed in the textbox.
$('#myTextBox').keyDown(function(){
// if the textbox is now longer empty
if($(this).val() != ""){
$('#myButoon').hide();
}
});
}
});
But checking if you are on a certain url for some actions doesn't seem like the best approach imho. You might want to look for different approach.
try this exampole
$(document).ready(function() {
checkTxt();
$("#txt").keyup(function() {checkTxt();});
});
function checkTxt(){
if (window.location.href.indexOf("fiddle") > -1 && $("#txt").val() == "")
$("#btn").hide();
}