.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

display data from database when id entered in textbox using javascript

Posted By: Catherine     Posted Date: April 18, 2011    Points:5   Category :VB.Net
Hi i want javascript for,when i enter employeeid in textbox data(Name,Address,city.country,state,email) should display in the corresponding textbox when i press tab key


function showdata()
{
document.getElementById (' txtPasName').value = document.getElementById ('strName').value;
document.getElementById (' txtPIssue').value = document.getElementById ('strPlaceofissue').value;
document.getElementById (' txtAdr1').value = document.getElementById ('strAddress1').value;
document.getElementById (' txtAdr2').value = document.getElementById ('strAddress2').value;
document.getElementById (' txtCity').value = document.getElementById ('strCity'.value);
document.getElementById (' txtEmail').value = document.getElementById ('strEmail').value;
}

Responses
Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

hi,
you can use following code,

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function showdata(strName,strPlaceofissue,strAddress1,strAddress2,strCity,strEmail)
{
document.getElementById('txtPasName').value = strName;
document.getElementById('txtPIssue').value = strPlaceofissue;
document.getElementById('txtAdr1').value = strAddress1;
document.getElementById('txtAdr2').value = strAddress2;
document.getElementById('txtCity').value = strCity;
document.getElementById('txtEmail').value = strEmail;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmpId" runat="server"></asp:TextBox>
<asp:TextBox ID="txtPasName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtPIssue" runat="server"></asp:TextBox>
<asp:TextBox ID="txtAdr1" runat="server"></asp:TextBox>
<asp:TextBox ID="txtAdr2" runat="server"></asp:TextBox>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>


'vb code'

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strName, strPlaceofissue, strAddress1, strAddress2, strCity, strEmail As String
strName = "name1"
strPlaceofissue = "place"
strAddress1 = "add1"
strAddress2 = "add2"
strCity = "city"
strEmail = "email"

txtEmpId.Attributes.Add("onblur", "showdata('" & strName & "','" & strPlaceofissue _
& "','" & strAddress1 & "','" & strAddress2 _
& "','" & strCity & "','" & strEmail & "')")
End Sub


thanks
Mahesh

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

thanks i would like to know where i get values from database. where should i use my table_name and select query. how it bind the data .because i get value from database. please tell

Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

hi,
in the page load event i had declared string variables and assigned them values, only thing you need to do is write one function to connect to DB and fetch values once the values are fetched then assigned them to that string variables and rest will work as it is,

if any doubts replay, hope this will help you...

Thanks
Mahesh

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   


Hi Mahesh I wrote this code error coming when fill ( da.Fill(ds, "tblmycustomerdetails")) as can not be null. but i have data in database

connection = New OleDbConnection(connectionString)
connection.Open()

calldatabase()
Dim intpasid, intpasname, intdob, intexdate, intpois, intaddress, intcity, intstate, intcountry, intrph, intoph, intmobno, intmail As String
intpasid = "intPassengerId"
intpasname = "strName"
intdob = "datDOB"
intexdate = "datExpirydate"
intpois = "strPlaceofissue"
intaddress = "strAddress"
intcity = "strCity"
intstate = "strState"
intcountry = "strCountry"
intrph = "strResidenceph"
intoph = "strOfficeph"
intmobno = "strMobile"
intmail = "strEmail"

txtpassno.Attributes.Add("onblur", "showdata(" & intpasid & ",'" & intpasname & "','" & intdob & "','" & intexdate _
& "','" & intpois & "','" & intaddress & "','" & intcity & "','" & intstate & "','" & intcountry & "','" & intrph & "','" & intoph _
& "','" & intmobno & "','" & intmail & "')")

End Sub


Protected Sub calldatabase()
SQLstr = "select intPassengerId,strName,datDOB,datExpirydate,strPlaceofissue,strAddress,strCity,strState,strCountry,strResidenceph,strOfficeph,strMobile,strEmail from tblmycustomerdetails where strPassportNo='" & txtpassno.Text & "'"
da = New OleDbDataAdapter(SQLstr, connection)
da.Fill(ds, "tblmycustomerdetails")
connection.Close()
End Sub



javascript


function showdata(intpasid,intpasname,intdob,intexdate,intpois,intaddress,intcity,intstate,intcountry,intrph,intoph,intmobno,intmail)
{

document.getElementById('txtid').value =intpasid;
document.getElementById('txtname').value = intpasname;
document.getElementById('txtdob').value = intdob;
document.getElementById('txtexdate').value = intexdate;
document.getElementById('txtpois').value = intpois;
document.getElementById('txtadres').value = intaddress;
document.getElementById('txtcity').value = intcity;
document.getElementById('txtstate').value = intstate;
document.getElementById('txtcountry').value = intcountry;
document.getElementById('txtrph').value = intrph;
document.getElementById('txtoph').value = intoph;
document.getElementById('txtmobno').value = intmobno;
document.getElementById('txtmailid').value = intmail;

}


<asp:TextBox ID="txtpassno" onblur = "return showdata()" runat="server" Height="23px" Style="left: 548px; position: absolute;
top: 27px"></asp:TextBox>

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

hi Mahesh i am sorry my error solved. but when i give tab key it moves to another textbox not bind the data please help

Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

Hi Catherine,
change u r code as below,

Protected function calldatabase() as dataset
SQLstr = "select intPassengerId,strName,datDOB,datExpirydate,strPlaceofissue,strAddress,strCity,strState,strCountry,strResidenceph,strOfficeph,strMobile,strEmail from tblmycustomerdetails where strPassportNo='" & txtpassno.Text & "'"
da = New OleDbDataAdapter(SQLstr, connection)
da.Fill(ds, "tblmycustomerdetails")
connection.Close()
return ds
End function

while calling function,

dim oDs as dataset
ods = calldatabase()

if ods isnot nothing then

intpasid = ods.tables(0).rows(0).item("intPassengerId")
intpasname = ods.tables(0).rows(0).item("strName")
intdob = ods.tables(0).rows(0).item("datDOB")
intexdate = ods.tables(0).rows(0).item("datExpirydate")
intpois = ods.tables(0).rows(0).item("strPlaceofissue")
intaddress = ods.tables(0).rows(0).item("strAddress")
intcity = ods.tables(0).rows(0).item("strCity")
intstate = ods.tables(0).rows(0).item("strState")
intcountry = ods.tables(0).rows(0).item("strCountry")
intrph = ods.tables(0).rows(0).item("strResidenceph")
intoph = ods.tables(0).rows(0).item("strOfficeph")
intmobno = ods.tables(0).rows(0).item("strMobile")
intmail = ods.tables(0).rows(0).item("strEmail")

end if

put the error handling in it...

Thanks
Mahesh

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

hi mahesh its telling there is no row at position 0. but i have rows and all fields are correct

Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

Hi,
use following code in u r aspx page,

<input type="hidden" id="hid1" name="hid1" value="" onpropertychange="ClientCode()" />
<asp:Button runat="server" style="display:none;" id="btnProcess" ></asp:Button>


javascript code,

function ClientCode()
{
document.getElementById('btnProcess').click();
}

function showdata()
{
document.getElementById('hid1').value = document.getElementById('txtpassno').value;
}




in code file,

'page load event
txtpassno.Attributes.Add("onblur", "showdata()")



Private Sub PopulateData()
dim oDs as dataset
ods = calldatabase()

if ods isnot nothing andalso ods.tables.count = 1 andalso ods.tables(0).rows.count > 0 then

intpasid = ods.tables(0).rows(0).item("intPassengerId")
intpasname = ods.tables(0).rows(0).item("strName")
intdob = ods.tables(0).rows(0).item("datDOB")
intexdate = ods.tables(0).rows(0).item("datExpirydate")
intpois = ods.tables(0).rows(0).item("strPlaceofissue")
intaddress = ods.tables(0).rows(0).item("strAddress")
intcity = ods.tables(0).rows(0).item("strCity")
intstate = ods.tables(0).rows(0).item("strState")
intcountry = ods.tables(0).rows(0).item("strCountry")
intrph = ods.tables(0).rows(0).item("strResidenceph")
intoph = ods.tables(0).rows(0).item("strOfficeph")
intmobno = ods.tables(0).rows(0).item("strMobile")
intmail = ods.tables(0).rows(0).item("strEmail")

end if

end sub


Protected Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcess.Click
PopulateData()
End Sub

any doubt please replay...

Thanks
Mahesh

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

hi Mahesh i am sorry i already tried with button click it was work. now my higher authority told me to do in onchange or onblur event when tab key pressed

Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

hi,
its not completely button click event this method is called from javascript, also that button is hidden button along with hidden textbox, so i think it is different and it will fulfil u r req..

Thanks
Mahesh

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

thank you when i debug this line the dataset is empty what can i do tell. how to bind this

Public Function calldatabase()

SQLstr = "select intPassengerId,strName,datDOB,datExpirydate,strPlaceofissue,strAddress,strCity,strState,strCountry,strResidenceph,strOfficeph,strMobile,strEmail from tblmycustomerdetails where strPassportNo='" & txtpassno.Text & "'"
da = New OleDbDataAdapter(SQLstr, connection)
da.Fill(ds)
' da.Fill(ds, "tblmycustomerdetails")
Return ds


End Function

Author: Mahesh             
Posted Date: April 19, 2011     Points: 20   

thrs prob with u r query...re check it...check weather the datatype of strpassportno is int or varchar..

Author: Catherine             
Posted Date: April 19, 2011     Points: 20   

Its varchar

Author: Catherine             
Posted Date: April 20, 2011     Points: 20   

Hi Mahesh thank you so much. this is your code it works. but when i press tab third time works well. whats the solution for this

on page_load

connection = New OleDbConnection(connectionString)
connection.Open()
txtpassno.Attributes.Add("onblur", "showdata()")

Protected Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcess.Click
PopulateData()
End Sub
Private Sub PopulateData()
Dim oDs As dataset
ods = calldatabase()
Dim intpasid, intpasname, intdob, intexdate, intpois, intaddress, intcity, intstate, intcountry, intrph, intoph, intmobno, intmail As String
If ods IsNot Nothing AndAlso ods.tables.count = 1 AndAlso ods.tables(0).rows.count > 0 Then

intpasid = ods.tables(0).rows(0).item("intPassengerId")
intpasname = ods.tables(0).rows(0).item("strName")
intdob = ods.tables(0).rows(0).item("datDOB")
intexdate = ods.tables(0).rows(0).item("datExpirydate")
intpois = ods.tables(0).rows(0).item("strPlaceofissue")
intaddress = ods.tables(0).rows(0).item("strAddress")
intcity = ods.tables(0).rows(0).item("strCity")
intstate = ods.tables(0).rows(0).item("strState")
intcountry = ods.tables(0).rows(0).item("strCountry")
intrph = ods.tables(0).rows(0).item("strResidenceph")
intoph = ods.tables(0).rows(0).item("strOfficeph")
intmobno = ods.tables(0).rows(0).item("strMobile")
intmail = ods.tables(0).rows(0).item("strEmail")

txtid.Text = intpasid
txtname.Text = intpasname
txtdob.Text = intdob
txtexdate.Text = intexdate
txtpois.Text = intpois
txtadres.Text = intaddress
txtcity.Text = intcity
txtstate.Text = intstate
txtcountry.Text = intcountry
txtrph.Text = intrph
txtoph.Text = intoph
txtmobno.Text = intmobno
txtmailid.Text = intmail
connection.Close()
End If

End Sub

Public Function calldatabase()

SQLstr = "select intPassengerId,strName,datDOB,datExpirydate,strPlaceofissue,strAddress,strCity,strState,strCountry,strResidenceph,strOfficeph,strMobile,strEmail from tblmycustomerdetails where strPassportNo='" & txtpassno.Text & "'"
da = New OleDbDataAdapter(SQLstr, connection)
da.Fill(ds)
' da.Fill(ds, "tblmycustomerdetails")
Return ds
End Function




aspx page

function ClientCode()
{
document.getElementById('btnProcess').click();
}

function showdata()
{
document.getElementById('hid1').value = document.getElementById('txtpassno').value;
}


<asp:TextBox ID="txtpassno" onblur = "showdata()" runat="server" Height="23px" Style="left: 549px; position: absolute;
top: 29px" AutoPostBack="True"></asp:TextBox>
<input type="hidden" id="hid1" name="hid1" value="" onpropertychange="ClientCode()" />
<asp:Button runat="server" style="display:none;" id="btnProcess" ></asp:Button>

Author: Catherine             
Posted Date: April 20, 2011     Points: 20   

thank you thank you Mahesh now its work well

Author: Mahesh             
Posted Date: April 20, 2011     Points: 20   

Hi Catherine,
u r most welcome...

but still i will say this is not proper solution which i will prefer i am in hurry so i had given you this solution, i will prefer that you should get all employee data on page load and store it in cached memory and then try to pass this datatable to javascript function and then try to find the patient data in that as per ID entered, using this you can hily improve u r appln performance....but still gud to see that u r prob is solved...

Thanks
Mahesh

Author: Catherine             
Posted Date: April 20, 2011     Points: 20   

hi please give some idea about update panel and trigger without using autopostback=true. because it load the whole page and also tell about usecallback event


Author: Mahesh             
Posted Date: April 20, 2011     Points: 20   

hi,
Update panel enables us to partially rendere without a postback for the sections of a page, you may notice that there are two child elements of an UpdatePanel control. The most-frequently seen element is the <ContentTemplate> element, which essentially encapsulates the content that will be held by the update panel (the content for which we are enabling partial rendering). The other element is the <Triggers> element, which specifies the controls on the page (or the user control, if you are using one) that will trigger a partial render of the UpdatePanel control in which the <Triggers> element resides. U can put EnablePartialRendering="true" in script manager tag and partially render controls

The <Triggers> element can contain any number each of two child nodes: <asp:AsyncPostBackTrigger> and <asp:PostBackTrigger>. They both accept two attributes, ControlID and EventName, and can specify any Control within the current unit of encapsulation (for instance, if your UpdatePanel control resides within a Web User Control, you should not attempt to reference a Control on the Page on which the User Control will reside).

The <asp:AsyncPostBackTrigger> element is particularly useful in that it can target any event from a Control that exists as a child of any UpdatePanel control in the unit of encapsulation, not just the UpdatePanel under which this trigger is a child. Thus, any control can be made to trigger a partial page update.

Similarly, the <asp:PostBackTrigger> element can be used to trigger a partial page render, but one that requires a full round-trip to the server. This trigger element can also be used to force a full page render when a control would otherwise normally trigger a partial page render (for instance, when a Button control exists in the <ContentTemplate> element of an UpdatePanel control). Again, the PostBackTrigger element can specify any control that is a child of any UpdatePanel control in the current unit of encapsulation.

for more info please folow the link,
http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers

Thanks & Regards
Mahesh

Author: Catherine             
Posted Date: April 21, 2011     Points: 20   

hi Mahesh ini the above code i have added one field dropdownlist(Branchnames). how to bind data in dropdownlist when tab press after enter id in textbox

Author: Mahesh             
Posted Date: April 21, 2011     Points: 20   

hi,
you can select value in dropdownlist using following function,

function SelectMyItem(itemToSelect)
{
// Get a reference to the drop-down
var myDropdownList = document.frmSelect.ddlBranchnames;

// Loop through all the items
for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
{
if (myDropdownList.options[iLoop].value == itemToSelect)
{
// Item is found. Set its selected property, and exit the loop
myDropdownList.options[iLoop].selected = true;
break;
}
}
}


Thanks
Mahesh

Author: Catherine             
Posted Date: April 25, 2011     Points: 20   

thank you

Author: Mahesh             
Posted Date: April 25, 2011     Points: 20   

u r most welcome...



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend