Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to transfer the collected values of javascript in ajax

How to transfer the collected values of javascript in ajax

Scheduled Pinned Locked Moved ASP.NET
databasejavascripthelptutorialquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muc_
    wrote on last edited by
    #1

    Greetings .. I sit for several hours before the problem and still can not find a suitable answer. Javascript is not exactly my forte, so I just ask once. I want to do the following: I have a matrix with various Checbox. This will be filled by a database in C #. If a checkbox has been clicked, ie onclick, an inquiry should be sent to the database to read from the DataBase If click the checkbox in the matrix on C #, now is the time a database query with a WHERE = presentValue be started. http://img17.imageshack.us/img17/760/unbenanntpw.jpg From the database should be read out what people can C #. My problem is mainly in the transfer the collected values of javascript in ajax so that the database sends the request to obtain an answer? I am grateful for any information

    K D 2 Replies Last reply
    0
    • M Muc_

      Greetings .. I sit for several hours before the problem and still can not find a suitable answer. Javascript is not exactly my forte, so I just ask once. I want to do the following: I have a matrix with various Checbox. This will be filled by a database in C #. If a checkbox has been clicked, ie onclick, an inquiry should be sent to the database to read from the DataBase If click the checkbox in the matrix on C #, now is the time a database query with a WHERE = presentValue be started. http://img17.imageshack.us/img17/760/unbenanntpw.jpg From the database should be read out what people can C #. My problem is mainly in the transfer the collected values of javascript in ajax so that the database sends the request to obtain an answer? I am grateful for any information

      K Offline
      K Offline
      Kannan Ar
      wrote on last edited by
      #2

      Create a string contains the values using javascript and submit to server as a query string. In the server, you have to implement the logic to filter the values.

      M 1 Reply Last reply
      0
      • K Kannan Ar

        Create a string contains the values using javascript and submit to server as a query string. In the server, you have to implement the logic to filter the values.

        M Offline
        M Offline
        Muc_
        wrote on last edited by
        #3

        thanks for the answer I create a string contains the values using javascript and submit to server as a query string. In the server, you have to implement the logic to filter the values. I collect my values with a JavaScriptFunction

        function GetAllChecked() {
        var checkboxes = document.getElementsByName("skill");
        var s = ""

                for (var i = 0; i < checkboxes.length; i++)
                    if (checkboxes\[i\].checked)
                        s += checkboxes\[i\].value + ";"
                    ;
                    ;
        

        document.getElementById("hhidAcrobat").value = S;

            }
        

        exactly what I'm doing wrong?

        K D 2 Replies Last reply
        0
        • M Muc_

          Greetings .. I sit for several hours before the problem and still can not find a suitable answer. Javascript is not exactly my forte, so I just ask once. I want to do the following: I have a matrix with various Checbox. This will be filled by a database in C #. If a checkbox has been clicked, ie onclick, an inquiry should be sent to the database to read from the DataBase If click the checkbox in the matrix on C #, now is the time a database query with a WHERE = presentValue be started. http://img17.imageshack.us/img17/760/unbenanntpw.jpg From the database should be read out what people can C #. My problem is mainly in the transfer the collected values of javascript in ajax so that the database sends the request to obtain an answer? I am grateful for any information

          D Offline
          D Offline
          dojohansen
          wrote on last edited by
          #4

          It's not very clear (at least to me) what exactly the problem is. Nor can we know what AJAX implementation you are using - and there are many available. You could of course create your own ajax implementation, but it may be a good idea to take a look at what's out there first since you'll probably find something that fits your needs and can handle more than you need too, which is good since you'll then be less likely to have to find another as requirements evolve (and they *always* evolve, unless the app is so unsuccessful that it's scrapped right away). In general, what you're describing would consist of the following steps: 1) Collect the information that is necessary in order to query the database from the UI. Since the UI is in the browser, you'll most likely do this in JavaScript. 2) Send a request to the web server that indicates an operation and includes the above information. This too is in JavaScript, but how exactly depends on what AJAX implementation you're using. 3) On the web server, build an IDbCommand (e.g. an SqlCommand) to query the database or call a stored procedure, and execute it to get the information you need and/or do any other work the operation includes. 4) Return something to the client. What to return depends entirely on your requirements. You should always include some indication of success or failure, so the client can inform the user in the event of an error. It may be useful to include debugging information at least in your dev environment, such as an exception stack trace. If the UI is going to display data as a result of the operation, you have the choice of returning the data and use DHTML and JavaScript to modify the UI (more scalable), or rendering the HTML server-side and return it to the client (more powerful if you use an AJAX framework that allows you to do this). There is a "default" ajax-implementation of asp.net, and although it's not very high performance it may be a good choice (and probably fast enough). Google for "asp.net callbacks" and "asp.net updatepanel" to find tons of tutorials, documentation and code. The great thing about this implementation is that it plays nice in combination with normal postbacks. (Changing almost anything on the client with js can cause problems (related to viewstate), but asp.net callbacks do not, which is both why it may be good and why it's slower than some "pure" ajax implementations.) If you are already using some third-party ajax framework or a custom implementation of your own, at least clarify what

          M 1 Reply Last reply
          0
          • M Muc_

            thanks for the answer I create a string contains the values using javascript and submit to server as a query string. In the server, you have to implement the logic to filter the values. I collect my values with a JavaScriptFunction

            function GetAllChecked() {
            var checkboxes = document.getElementsByName("skill");
            var s = ""

                    for (var i = 0; i < checkboxes.length; i++)
                        if (checkboxes\[i\].checked)
                            s += checkboxes\[i\].value + ";"
                        ;
                        ;
            

            document.getElementById("hhidAcrobat").value = S;

                }
            

            exactly what I'm doing wrong?

            K Offline
            K Offline
            Kannan Ar
            wrote on last edited by
            #5

            Did you debug this code? what is the value of variable s after the loop? how you submit this value to server?

            M 1 Reply Last reply
            0
            • M Muc_

              thanks for the answer I create a string contains the values using javascript and submit to server as a query string. In the server, you have to implement the logic to filter the values. I collect my values with a JavaScriptFunction

              function GetAllChecked() {
              var checkboxes = document.getElementsByName("skill");
              var s = ""

                      for (var i = 0; i < checkboxes.length; i++)
                          if (checkboxes\[i\].checked)
                              s += checkboxes\[i\].value + ";"
                          ;
                          ;
              

              document.getElementById("hhidAcrobat").value = S;

                  }
              

              exactly what I'm doing wrong?

              D Offline
              D Offline
              dojohansen
              wrote on last edited by
              #6

              I don't know what element "skill" is, but there is no HTML element that represents a "checkboxlist" so I'm guessing it's a container for the checkboxes. Try changing the first line to

              var checkboxes = document.getElementsByName("skill").children;

              If it still doesn't work, attach your debugger and use the watches to see what's in the variables. If you don't know how to do this, take the time to learn it as it'll save you a huge amount of time in the long run.

              M 1 Reply Last reply
              0
              • K Kannan Ar

                Did you debug this code? what is the value of variable s after the loop? how you submit this value to server?

                M Offline
                M Offline
                Muc_
                wrote on last edited by
                #7

                the value of my string in Js contain "43;44;45;46;47;48;49;50;51;52;53;54;" how should i tranfer this string to my database?

                K 1 Reply Last reply
                0
                • D dojohansen

                  I don't know what element "skill" is, but there is no HTML element that represents a "checkboxlist" so I'm guessing it's a container for the checkboxes. Try changing the first line to

                  var checkboxes = document.getElementsByName("skill").children;

                  If it still doesn't work, attach your debugger and use the watches to see what's in the variables. If you don't know how to do this, take the time to learn it as it'll save you a huge amount of time in the long run.

                  M Offline
                  M Offline
                  Muc_
                  wrote on last edited by
                  #8

                  Its look so: http://img17.imageshack.us/img17/760/unbenanntpw.jpg[] I have all the check boxes "skill named" so that I can read me on a train all checked values. therefore they are called Skill ..

                  1 Reply Last reply
                  0
                  • M Muc_

                    the value of my string in Js contain "43;44;45;46;47;48;49;50;51;52;53;54;" how should i tranfer this string to my database?

                    K Offline
                    K Offline
                    Kannan Ar
                    wrote on last edited by
                    #9

                    Post this string as a query string to the target URL using XMLHttpRequest object.

                    M 1 Reply Last reply
                    0
                    • D dojohansen

                      It's not very clear (at least to me) what exactly the problem is. Nor can we know what AJAX implementation you are using - and there are many available. You could of course create your own ajax implementation, but it may be a good idea to take a look at what's out there first since you'll probably find something that fits your needs and can handle more than you need too, which is good since you'll then be less likely to have to find another as requirements evolve (and they *always* evolve, unless the app is so unsuccessful that it's scrapped right away). In general, what you're describing would consist of the following steps: 1) Collect the information that is necessary in order to query the database from the UI. Since the UI is in the browser, you'll most likely do this in JavaScript. 2) Send a request to the web server that indicates an operation and includes the above information. This too is in JavaScript, but how exactly depends on what AJAX implementation you're using. 3) On the web server, build an IDbCommand (e.g. an SqlCommand) to query the database or call a stored procedure, and execute it to get the information you need and/or do any other work the operation includes. 4) Return something to the client. What to return depends entirely on your requirements. You should always include some indication of success or failure, so the client can inform the user in the event of an error. It may be useful to include debugging information at least in your dev environment, such as an exception stack trace. If the UI is going to display data as a result of the operation, you have the choice of returning the data and use DHTML and JavaScript to modify the UI (more scalable), or rendering the HTML server-side and return it to the client (more powerful if you use an AJAX framework that allows you to do this). There is a "default" ajax-implementation of asp.net, and although it's not very high performance it may be a good choice (and probably fast enough). Google for "asp.net callbacks" and "asp.net updatepanel" to find tons of tutorials, documentation and code. The great thing about this implementation is that it plays nice in combination with normal postbacks. (Changing almost anything on the client with js can cause problems (related to viewstate), but asp.net callbacks do not, which is both why it may be good and why it's slower than some "pure" ajax implementations.) If you are already using some third-party ajax framework or a custom implementation of your own, at least clarify what

                      M Offline
                      M Offline
                      Muc_
                      wrote on last edited by
                      #10

                      That there is a updateplanel I have seen. It loads only a portion of the site. And my portion, the user should be having my skills.

                      1 Reply Last reply
                      0
                      • K Kannan Ar

                        Post this string as a query string to the target URL using XMLHttpRequest object.

                        M Offline
                        M Offline
                        Muc_
                        wrote on last edited by
                        #11

                        thx for ya idea, will try it

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups