JQuery not passing data from form to server table

My data is not passing from the form to the function in the scripot tag to to pass to to the server....am I doing something wroing, here I think I have the right logic... thanks
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import namespace ="System.data" %>
<%@ Import namespace ="System.data.SqlClient" %>

<script runat="server">
    
    Protected Sub data_to_db(ByVal sender As Object, ByVal e As System.EventArgs)
        
        Dim SQLConn1 As SqlConnection = New SqlConnection()
        Dim cmd1 As SqlCommand
        Dim SQLStr1 As String
        Dim err1 As String
        Dim code As String
        
        SQLConn1.ConnectionString = "Network Library=DBMSSOCN; Data Source=Server Address, server port; Intial Catalog=database name; User Id;Password;"
        SQLStr1 = ("INSERT INTO Product (phrase) VALUES ('" & code & "')")
        cmd1 = New SqlCommand(SQLStr1, SQLConn1)
        
        Try
            err1 = cmd1.ExecuteNonQuery()
        Catch ex As Exception
        Finally
            SQLConn1.Close()
        End Try
    End Sub
                    
        
   
</script>

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26689661.html</title>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="stylesheet" href="http://jquery.bassistance.de/tooltip/jquery.tooltip.css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js" language="javascript" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">

$(function() {

  $("#hot-area").keyup( keyUp );

});

var touched = false;
var timer;
function keyUp( event ) {
  if ( timer != null ) clearTimeout( timer );
  timer = setTimeout( timeExpired, 3000 );
  if ( !touched ) {
    touched = true;
    var code = event.keyCode;
    if ( event.shiftKey == false ) code |= 0x20;
    $("#hot-area").text( String.fromCharCode( code ) );
    
    /* Now feed to db every time there is data*/
    feed_to_db(code)
  }
}

function timeExpired() {
    /* Pick random number between 1 and 10 */     
    var randomNum = Math.ceil(Math.random()*2); 
 
    if(randomNum == 1 )
        $("#hot-area").text( "Test1..." );
        touched = false;
    
    if(randomNum == 2 )
        $("#hot-area").text( "test2..." );
        touched = false;
       
}

 function feed_to_db(var code)(
   /* Now pass the data to the runat to call func to send data to server*/
   /* http://www.dotnetspark.com/kb/1453-call-server-side-function-using-jquery-asp-net.aspx*/
                $.ajax({
                    type: "POST",
                    //Page Name (in which the method should be called) and method name
                    url: "test1.aspx/data_to_db",
                    // If you want to pass parameter or data to server side function you can try line
                    //data: "{'args':'Pankaj'}",
                    //else If you don't want to pass any value to server side function leave
                    data: "{code}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        //Got the response from server and render to the client
                        msgbox.html(msg.d);
                    } 
 
 )
 
 
</script>


  
</head>
<body>

<textarea id="hot-area" cols="80" rows="20">I'm waiting for you to type in here...</textarea>

</body>
</html>

Open in new window

LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Salim FayadCommented:
But the function data_to_db takes 2 parameters while you are passing only one
Bruce SmithSoftware Engineer IICommented:
The_eagle is right, Line #88 in your post above should pass two variables. And also, Line #16 declares the String variable 'code' and the default value there will be an empty String. And on Line #19 you are inserting the empty String variable 'code' into your SQL. So the variable(s) that you're passing into the data_to_db method are never getting used. Try something like this with your data_to_db method without modifying your JQuery code:

 
Protected Sub data_to_db(ByVal codeParam As String)
        
        Dim SQLConn1 As SqlConnection = New SqlConnection()
        Dim cmd1 As SqlCommand
        Dim SQLStr1 As String
        Dim err1 As String
        Dim code As String
        code = codeParam
        
        SQLConn1.ConnectionString = "Network Library=DBMSSOCN; Data Source=Server Address, server port; Intial Catalog=database name; User Id;Password;"
        SQLStr1 = ("INSERT INTO Product (phrase) VALUES ('" & code & "')")
        cmd1 = New SqlCommand(SQLStr1, SQLConn1)
        
        Try
            err1 = cmd1.ExecuteNonQuery()
        Catch ex As Exception
        Finally
            SQLConn1.Close()
        End Try
    End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Salim FayadCommented:
In addition to patsmitty, if you used his code, then the "data" in line 88 should be as following
data: "{codeParam : 'Pankaj'}"

Open in new window

OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

shubham_gniiitCommented:
GlobaLevelProgrammerAuthor Commented:
okay i will look tnite...
GlobaLevelProgrammerAuthor Commented:
Hi rkworlds...I was attempting close and divide points up equally between the 'The Eagle' and 'shubham_gniiit'...it wouldn't let me..thanks
GlobaLevelProgrammerAuthor Commented:
rkworlds,

thank you
Kumaraswamy RCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.