I have an Asp.net
application which I have a JQuery
function which disables/enables my 'Submit' button. At present my 'Submit' button is disabled if any of my fields are blank but I now want to add another condition to it to see if my error message is displayed or not.
My message is displayed on the server side so if the name already exists an error message is displayed as soon as you tab out the field (All this works fine).
I cant get it to work at all.
HTML of label
<asp:Label id="placeExists" runat="server" Text="The place you suggested already exists in the list of 'Places'." Visible="false" style="color: red"></asp:Label>
Current JQuery
//Disables/Enables submit button on modal
$("#MainContent_fldPlace").on("blur", function ()
{
disableButton();
});
$("#MainContent_fldLocation").on("blur", function ()
{
disableButton();
});
$("#MainContent_fldName").on("blur", function ()
{
disableButton();
});
function disableButton()
{
if ($('#MainContent_fldPlace').val() != '' && $('#MainContent_fldLocation').val() != '' && $('#MainContent_fldName').val() != '')
{
$("#MainContent_btnSubmitNewPlace").prop('disabled', false);
}
else
{
$("#MainContent_btnSubmitNewPlace").prop('disabled', true);
}
}
////////
I tried adding:
$('#MainContent_placeExists').visible == true
to my IF
but it didn't work
Below is my code behind for the show/hide of the label on server side
#region Checks if the place exists in 'Places' db when field clicked out of
protected void fldPlace_TextChanged(object sender, EventArgs e)
{
//Keeps the 'Suggest A Place' modal open
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "keepOpenSuggestPlaceModal();", true);
if (!string.IsNullOrEmpty(fldPlace.Text))
{
string connection = ConfigurationManager.ConnectionStrings["PaydayLunchConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT 1 FROM Places WHERE Place = @Place", conn);
cmd.Parameters.AddWithValue("@Place", fldPlace.Text);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.HasRows)
{
placeExists.Visible = true;
}
else
{
placeExists.Visible = false;
}
}
}
#endregion
Rendered HTML from website
<div class="modal-body">
<p>If you would like to suggest a place please populate the fields below and click 'Submit'.</p>
<p>Your request will then be reviewed by a site administrator and if accepted, it will be added to the list.</p>
<span id="MainContent_placeExists" style="color: red;">The place you suggested already exists in the list of 'Places'.</span>
<div class="col-sm-offset-2">
<div class="form-group">
<label class="col-sm-3 control-label" id="MainContent_lblPlace" for="MainContent_fldPlace">Place</label>
<div class="col-sm-6">
<input name="ctl00$MainContent$fldPlace" class="form-control" id="MainContent_fldPlace" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MainContent$fldPlace\',\'\')', 0)" type="text" value="Blaize">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" id="MainContent_lblLocation" for="MainContent_fldLocation">Location</label>
<div class="col-sm-6">
<input name="ctl00$MainContent$fldLocation" class="form-control" id="MainContent_fldLocation" type="text">
</div>
</div>
<div class="row">
<label class="col-sm-3 control-label" id="MainContent_lblName" for="MainContent_fldName">Your Name</label>
<div class="col-sm-6">
<input name="ctl00$MainContent$fldName" class="form-control" id="MainContent_fldName" type="text">
</div>
</div>
</div>
</div>