Home > Back-end >  Fill input field based on another in Razor forms
Fill input field based on another in Razor forms

Time:01-20

I have these 2 input text and I need to fill the second one, the disabled one, when the user inputs a valid ID and tabs out of the first one with a patient name that I get from a database

<input type="text"  maxlength="8" @onblur="lostFocus" />
<input type="text"  id="name" name="Name"  disabled>

@code {
    public void lostFocus()
    {
        Patient c = new Patient();
        c = PatientService.GetPatientByStudyID (id);
        
        //code to fill the disabled Input.
    }
}

Is there a way to do it without JavaScript?

CodePudding user response:

Just create a name property and set this property value with patient Name:

<input type="text"  maxlength="8" @onblur="lostFocus" />
                                                            //add value="@name"
<input type="text"  id="name" name="Name" value="@name" disabled>

@code {
    public string name { get; set; } = "";
    public void lostFocus()
    {
        Patient c = new Patient();
        c = PatientService.GetPatientByStudyID (id);
        
        //code to fill the disabled Input.
        name = c.Name; 
    }
    public class Patient
    {
        public string Name { get; set; }
    }
}
  • Related