I need to transliterate the names of employees that are fetched from my database and write the transliterated values back into the database... For this I need to run a javascript code in a loop for as many no of records as in the database....

The code I am currently using is


Dim cmd As New SqlCommand("select empname from tbl_emp", conobject)
            Dim dr As SqlDataReader
            dr = cmd.ExecuteReader
            Dim i As Integer = 1

            While dr.Read
             Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "b" & i, "<script>conurdu('" & dr(0) & "');</script>")
                Response.Write (txt_result.Text)
                i = i + 1
            End While


        <script type="text/javascript">

        function conurdu(fieldname) {
        google.language.transliterate([fieldname], "en", "ur", function(result) {

            if (!result.error) 
             if (result.transliterations && result.transliterations.length > 0 && result.transliterations[0].transliteratedWords.length > 0) 
                    document.getElementById(<%=txt_result.ClientID%>).value = result.transliterations[0].transliteratedWords[0] ;

For example, there are five records in the database, only the last one gets written in the txt_result textbox...
Any ideas???

Edited by nice_true

3 Years
Discussion Span
Last Post by stbuchok

Wouldn't it be better to make an AJAX call for the list of names and then loop through for translation and once the translation is done, make another AJAX call to update?

Also on line 10, you are missing quotes for the id that you are looking for.

try this instead: document.getElementById('<%=txt_result.ClientID%>')

One last thing, which is about you actual issue. You are only getting the last one because each time you write to txt_result, it is overriding the last value. use += instead of = on line 10.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.