Results 1 to 7 of 7
  1. #1
    happy is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default using java code inside javascipt-- in jsp

    i am nt able to post d marks obtained by a student to the corresponding database. i have used javascript to handle the onsubmit event of the form, bt im nt able to retain the javascript's variable's value in my java code.

    here z d code..


    <script language="javascript">

    function f11()
    {
    alert("entererddd");
    var result=0;
    x= document.f1;
    if(x.r1[0].checked || x.r1[1].checked || x.r1[2].checked || x.r1[3].checked)
    {
    if(x.r1[0].checked)
    {
    alert("monkey");
    result=result+1;
    result1=result1+1;
    alert(result1);


    }

    if(x.r1[1].checked)
    {
    alert(" dog ");

    }

    if(x.r1[2].checked)
    {
    msgbox("hello");
    System.out.println("chekd here");
    alert("donkey ");
    }
    if(x.r1[3].checked)
    alert("cat ");

    }


    if(x.r2[0].checked || x.r2[2].checked || x.r2[3].checked || x.r2[1].checked)
    {
    alert("2nd entrd");
    if(x.r2[0].checked)
    {
    alert("crab");
    result=result+1;
    result1=result1+1;
    }

    if(x.r2[1].checked)
    alert("snake");

    if(x.r2[2].checked)
    alert("dog");

    if(x.r2[3].checked)
    alert("cockroach");


    }

    alert(result);

    }
    </script>
    </head>

    <BODY bgcolor="red">


    <H1> <center>ONLINE MCQ EXAM</center></H1>




    <H2> QUESTION1: </H2>

    <b>NATIONAL ANIMAL:</b>



    <form name="f1">
    monkey:<input type="radio" name="r1" ><br>
    DOG:<input type="radio" name="r1" ><br>
    donkey:<input type="radio" name="r1"><br>
    cat: <input type="radio" name="r1"><br><br>


    <h2>Question2:</h2>
    <h3> which of the following seems delicious to u:</h3>
    crab:<input type="radio" name="r2" ><br>
    snake:<input type="radio" name="r2" ><br>
    dog:<input type="radio" name="r2"><br>
    cockroach: <input type="radio" name="r2">


    <br><br><br><br>
    <center>
    <input type="button" value="submit" name="b1" onclick="f11();">

    </center>
    </form>




    <%@page import="java.sql.*" %>
    <%


    HttpSession s1= request.getSession();
    Object o1=s1.getAttribute("Username");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String str=o1.toString();

    Connection con= DriverManager.getConnection("jdbc:odbc:mydsn","hap py","happy");
    Statement stmt= con.createStatement();

    PreparedStatement pst= con.prepareStatement("update student set marks=? where name=?");
    pst.setInt(1, result1);
    pst.setString(2, str);
    PreparedStatement ps1=con.prepareStatement("commit;");


    </BODY>
    </HTML>

  2. #2
    happy is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default

    pls do reply ASAP.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default

    "ASAP"

    db

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    jvaScpt is to Jva as hm is to hmstr.

    Am I doing it rght?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    To summarise.
    We're not here to do your bidding, so ASAP is simply rude.

    Txt spk is a pain to read. Anything that makes it harder for us to read your post makes it harder for us to help you. The easier you make it for us the more likely you are to get help.

    Finally, Javascript runs on the client. Java runs on the server.

  6. #6
    happy is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Post

    i'm sorry to say ASAP .
    bt i was to present it by 2day itself . so i thought of getting a quick help .
    i didn't intend to be rude.

    actually i m new 2 dis forum , so didn't knw how 2 attach files. so i just copied d code snippet.

    thnks fr ur reply..

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    I notice you're still txt spkng.
    Either you have a broken keyboard (which will make coding rather difficult) or you didn't understand what was posted.

Similar Threads

  1. Replies: 9
    Last Post: 04-12-2011, 08:26 PM
  2. Replies: 5
    Last Post: 05-25-2009, 10:03 PM
  3. Replies: 6
    Last Post: 02-06-2009, 09:05 PM
  4. javascipt function is nt getting called
    By pankaj_salwan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-20-2008, 09:13 AM
  5. show a value in javascipt in the jsp page
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-20-2008, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •