Avatar of john8694
john8694
Flag for United States of America

asked on 

How Do I Auto Populate An Text Field With Text From Another Field?

I am attempting to modify a page on our internal website (written in ASP).  Right now the user enters information into the field for "user name:", then enters the email address in the "e-mail:" field.  The email address in our company always follows the same pattern, so I would like for the email address to auto-populate once the name field is entered.

Here is most of the code on that page:

Call CheckRep(cnnDB, sid)
 
  Dim blnSubmitNew, strSubmitResults
  If Cint(Request.Form("save")) = 1 Then
    blnSubmitNew = True
  Else
    blnSubmitNew = False
  End If
 
  ' ==============================================
  ' Save problem
  If blnSubmitNew Then
    ' Get the information from the form fields
    Dim uid, uemail, uphone, ulocation, category, department, title, description
    Dim priority, status, rep, time_spent, solution, entered_by, uselectid, kb
 
    uselectid = Request.Form("uselectid")
    uid = Request.Form("uid")
    uemail = Request.Form("uemail")
    uphone = Request.Form("uphone")
    ulocation = Request.Form("ulocation")
    category = Cint(Request.Form("category"))
    department = Request.Form("department")
    title = Request.Form("title")
    description = Request.Form("description")
    priority = Cint(Request.Form("priority"))
    status = Cint(Request.Form("status"))
    rep = Cint(Request.Form("rep"))
    time_spent = Cint(Request.Form("time_spent"))
    solution = Request.Form("solution")
 
    If Request.Form("kb") = "on" Then
      kb = 1
    Else
      kb = 0
    End If
 
    ' Check for required fields (uemail, category, department, title, description)
    If uselectid <> 0 then 
      uid = usr(cnnDB, uselectid, "uid") 
      uemail = usr(cnnDB, uselectid, "email1") 
      uphone = usr(cnnDB, uselectid, "phone") 
      ulocation = usr(cnnDB, uselectid, "location1") 
      department = usr(cnnDB, uselectid, "department") 
    Else 
      If Len(uid)=0 Then
        Call DisplayError(1, lang(cnnDB, "UserName"))
      End if
 
      if uemail = Cfg(cnnDB, "BaseEmail") Then
        Call DisplayError(1, lang(cnnDB, "EMailAddress"))
      End if
    End If
 
    if category = 0 Then
      Call DisplayError(1, lang(cnnDB, "Category"))
    End if
 
    if (department = 0) And (uselectid = 0) Then
      Call DisplayError(1, lang(cnnDB, "Department"))
    End if
 
    if Len(title)=0 Then
      Call DisplayError(1, lang(cnnDB, "Title"))
    Elseif Len(title) > 50 Then
      title = Trim(title)
      title = Left(title, 50)
    End if
 
    if Len(description)=0 Then
      Call DisplayError(1, lang(cnnDB, "Description"))
    End if
 
    if (status=Cfg(cnnDB, "CloseStatus")) and (Len(solution)=0) Then
      Call DisplayError(1, lang(cnnDB, "Solution"))
    End if
 
    ' Get missing variables to enter problem
    Dim id
 
    Dim dname, depRes
    Set depRes = SQLQuery(cnnDB, "SELECT dname FROM departments WHERE department_id=" & Request.Form("department"))
    dname = depRes("dname")
 
    Dim cname, catRes
    Set catRes = SQLQuery(cnnDB, "SELECT cname, rep_id FROM categories WHERE category_id=" & Request.Form("category"))
    cname = catRes("cname")
 
    entered_by = sid
 
    ' Get the problem ID number then immediately update it
    id = GetUnique(cnnDB, "problems")
 
    ' Convert strings to valid SQL strings
    On Error Resume Next
    uphone = Replace(uphone,"'","''")
    ulocation = Replace(ulocation,"'","''")
    title = Replace(title,"'","''")
    description = Replace(description,"'","''")
    solution = Replace(solution,"'","''")
    On Error Goto 0
 
    ' All data is present
    ' Write problem into database
    Dim probStr
 
    ' If status is closed, then include the closed date/time
      If status = Cfg(cnnDB, "CloseStatus") Then
        probStr = "INSERT INTO problems (id, uid, uemail, uphone, ulocation, " & _
        "category, department, title, description, priority, status, start_date, rep, time_spent, " & _
        "close_date, entered_by, solution, kb) " & _
        "VALUES (" & id & ",'" & uid & "','" & uemail & "','" & uphone & "','" & _
        ulocation & "'," & category & "," & department & ",'" & title & "','" & _
        description & "'," & priority & "," & status & "," & SQLDate(Now, lhdAddSQLDelim) & "," & rep & "," & time_spent & _
        "," & SQLDate(Now, lhdAddSQLDelim) & "," & entered_by & ",'" & solution & "', " & kb & ")"
      Else
        probStr = "INSERT INTO problems (id, uid, uemail, uphone, ulocation, " & _
        "category, department, title, description, priority, status, start_date, rep, time_spent, " & _
        "entered_by, solution, kb) " & _
        "VALUES (" & id & ",'" & uid & "','" & uemail & "','" & uphone & "','" & _
        ulocation & "'," & category & "," & department & ",'" & title & "','" & _
        description & "'," & priority & "," & status & "," & SQLDate(Now, lhdAddSQLDelim) & "," & rep & "," & time_spent & _
        "," & entered_by & ",'" & solution & "'," & kb & ")"
      End If

Open in new window

ASPCSSHTML

Avatar of undefined
Last Comment
john8694

8/22/2022 - Mon