when user if user leaves blank any step cursor to where error is taken (jquery)

Harun Ergün 65 Reputation points
2023-01-24T06:12:55.2933333+00:00

when user if user leaves blank any step cursor to where error is taken

For Example

var name = $('#name').val();

if (name == '') {
$('#name').css('border-color', 'red');
alert('Please write your first and last name')
return false;

} else {
$('#name').css('border-color', 'black');

}


(ASP.NET MVC WEB)

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,292 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.8K Reputation points
    2023-01-24T06:35:35.0033333+00:00

    Try executing $('#name').focus() before alert.

    And probably replace #name == '' with adSoyad == ''.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Harun Ergün 65 Reputation points
    2023-01-24T06:14:12.32+00:00

    ASP.net MVC Web

    0 comments No comments

  2. Harun Ergün 65 Reputation points
    2023-01-24T07:02:41.2133333+00:00
    No problem for textbox and drowboxlist. But I can't send to checkbox?
    
    var cinsiyetValue = $('#cinsiyetValue').val();
    
    if (cinsiyetValue == '') {
                    $('#cinsiyetValue').css('border-color', 'red');
                    $('#cinsiyetValue').focus()
                    alert('Lütfen Cinsiyet Seçiniz')
                    return false;
    
                } else {
                    $('#cinsiyetValue').css('border-color', 'black');
    
                }
    
    where's my wrong sir ?
    
    0 comments No comments