Forum Moderators: open
<script type="text/javascript" language="javascript">
function CustNameClear()
{
var FName = document.getElementById('tbFName');
var LName = document.getElementById('tbLName');
FName.value = '';
LName.value = '';
}
</script>Dim cbNewUser As New CheckBox
Dim tbFName As New TextBox()
Dim tbLName As New TextBox()
Dim DBGetCustCmd As SqlCommand = New SqlCommand("usp_Get_Barcode_Customer", DBConn)
DBGetCustCmd.CommandType = CommandType.StoredProcedure
DBGetCustCmd.Parameters.AddWithValue("@barcode", barcode)
If Not Page.IsPostBack Then
Dim reader As SqlDataReader = DBGetCustCmd.ExecuteReader()
Try
While reader.Read()
tbFName.Text = reader.Item("FName")
tbLName.Text = reader.Item("LName")
tbAddr1.Text = reader.Item("Addr1")
tbAddr2.Text = reader.Item("addr2")
tbCity.Text = reader.Item("city")
strState = reader.Item("state")
tbZip.Text = reader.Item("Zip")
If Not reader.Item("Zip4").ToString = Nothing Then
tbZip4.Text = reader.Item("Zip4")
End If
lbCouponType.Text = reader.Item("Description")
If Not reader.Item("Email").ToString = Nothing Then
tbEmail.Text = reader.Item("Email")
End If
If Not reader.Item("Phone").ToString = Nothing Then
tbPhone.Text = reader.Item("Phone")
End If
End While
Finally
reader.Close()
End Try
End If
plNewUser.Controls.Add(cbNewUser)
cbNewUser.ID = "cbNewUser"
plFName.Controls.Add(tbFName)
plLName.Controls.Add(tbLName)
cbNewUser.Attributes.Add("onClick", "CustNameClear()")
<script type="text/javascript" language="javascript">
function CustNameClear()
{
var FName = document.getElementById('tbFName');
var LName = document.getElementById('tbLName');
FName.value = '';
LName.value = '';
}
</script>
..........
Dim tbFName As New TextBox()
Dim tbLName As New TextBox()
....
tbFName.Text = reader.Item("FName")
tbLName.Text = reader.Item("LName")
Tell me, is New Textbox() an internal command that creates the text field or is is a function you wrote yourself? Does it create input type="text" or a textarea? (either should work, presuming text input.) If it's internal, review the documentation; if you wrote it yourself, easy enough - the text box is most likely missing an id attribute:
<input type="text" name="tbFName" id="tbFName">
or
<textarea name="tbFName" id="tbFName"></textarea>
Looking at your ASP, it might be as simple as
tbFName.Attributes.Add("id", "tbFName")
tbLName.Attributes.Add("id", "tbLName")
It's perfectly legitimate to have the name and ID the same value; the exception is form array objects, such as radio buttons, where all items in the array have the same name but you must add a different ID for each member. ID's must be unique in the context of the document.
If it's already generating an ID field, then it's something else, possibly invalid HTML breaking the Javascript. An aside, and unrelated, it's always best to test for document.GetElementById first, avoiding sporadic errors:
<script type="text/javascript">
function CustNameClear() {
if (document.getElementById) {
document.getElementById('tbFName').value='';
document.getElementById('tbLName').value='';
}
}
</script>