pass value from javascript to jsp or html??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yadagereavinash
    New Member
    • Dec 2010
    • 7

    #1

    pass value from javascript to jsp or html??

    Friends,

    Plz tell me how to pass a value from javascript to html or jsp??

    Sample code will be more helpful.

    Thanks in Advance
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    You can try following.

    Code:
    <script type="text/javascript">
    function () {
         document.forms.myform.textfield.value = "some value";
    }
    </script>
    Regards
    Dheeraj Joshi

    Comment

    • yadagereavinash
      New Member
      • Dec 2010
      • 7

      #3
      Hi Dheeraj,

      Thanks a lot for your reply. Will try that code.

      Dude I am stuck with another problem can you please help?

      I want to to connect to mysql database using jsp.
      But I am getting an exception at line
      Class.forName(" com.mysql.jdbc. Driver");

      I am not getting how to proceed. So plz help.

      Can you send me a simple example on the same?

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        You need the JDBC driver for data base connection. The error implies it can not find the driver in the location.

        Set the class path properly.

        Regards
        Dheeraj Joshi

        Comment

        • yadagereavinash
          New Member
          • Dec 2010
          • 7

          #5
          Dheeraj I didn't understand this piece of code you sent.

          <script type="text/javascript">
          function () {
          document.forms. myform.textfiel d.value = "some value";
          }
          </script>

          Actually I want to store a value present in Javascript to my jsp variable. How do I do that?

          Thanks in Advance

          Comment

          • RAKESH BALAIAH
            New Member
            • Dec 2010
            • 6

            #6
            Hi yadagereavinash ,

            First get to know the difference between javascript and JSP.
            Javascript is a client side scripting language whereas JSP is a servr side programming language.
            This means that your JSP is compiled and executed by the Server whereas your Javascript will be executed by the browser.
            So whenever you run a program your JSP first gets compiled and the resulting output is made into an HTML document and sent to the browser where the browser understands the HTML and scripts and displays the result.
            Thus it is difficult to assign the value of a Javascript variable to JSP.
            But there is possibility to assign your JSP variable value to javascript with limitations.

            As far as i have known i was not successful to assign JS variable to JSP.
            I've even posted this question in many other forums but couldnt get proper reply.

            Y cant u try something else for that like using AJAX or DHTML.

            If you find a solution for this, kindly let me know so that i can correct myself.
            Thanks and Regards,
            RAKHI

            Comment

            Working...