Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: help needed

  1. #1
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default help needed

    hi friends....i am stuck in my code

    i am trying to assign a value of javascript variable to a java variable but it is giving errors

    is there any way of doing this.....i searched a lot but found none

    any suggestion will be highly appreciated

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

    Default

    In what are you trying to do this?

  3. #3
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    In what are you trying to do this?
    i want to pass a value to a bean to do some operation which is stored in a javascript variable

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

    Default

    So you have some javascript in an html page?
    Is the Java in an applet or on the web server?

  5. #5
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    So you have some javascript in an html page?
    Is the Java in an applet or on the web server?
    i am implementing ajax in my html page and java is on web server

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

    Default

    So your Ajax call to the server will have to have a parameter in it containing the value held in the variable. Then on the server you can extract that in the usual way from the request (or whatever framework you happen to be using).

  7. #7
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    So your Ajax call to the server will have to have a parameter in it containing the value held in the variable. Then on the server you can extract that in the usual way from the request (or whatever framework you happen to be using).
    you are right....but that is one way.
    what if i want to use that parameter on the same page i.e that javascript variable

    Is there any way to assign the value of javascript variable in java variable

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

    Default

    Are you saying that you want the js variable to be sent to the server and then reset the js variable to something returned by the server?

  9. #9
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    i want to pass the value of js variable in a bean.....how is that possible??

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

    Default

    Do you understand how your browser communicates with the web server?
    You can't simply send a bean...especially since (as far as your browser is concerned) a bean is meaningless.

  11. #11
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    u put some code here to see exactly what u want
    Ramya:cool:

  12. #12
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Java Code:
    var date=frm.date1.value;
    var a=<%=nameObj.check(date)%>
    now the error is coming on line "var a=<%=nameObj.check(date)%>"
    that date cannot be resolved

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You can't do that.
    Java runs on the server.
    That javascript runs on the client after all the Java code has finished running.

  14. #14
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    You can't do that.
    Java runs on the server.
    That javascript runs on the client after all the Java code has finished running.
    ohhk....i willl do it with other ways
    thanx a lot

  15. #15
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    You can do..Iam storing some boolean in jsp and trying to assign the boolean to javascript.After assigning based on boolean type iam doing if..see below

    test.jsp
    ----------
    <%
    boolean inputFlag = true;
    %>
    <script language ="javascript">
    var flag = <%= inputFlag%>;
    if(flag )
    document.writeln("Hi");
    else
    document.writeln("Bye");

    </script>
    </HEAD>
    </HTML>
    Ramya:cool:

  16. #16
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    this is not what i asked
    well this is true but the reverse is not i.e you cannot assign the value of a js variable to a java variable and moreover my problem was that i was trying to pass the value of a js variable in a bean which was giving errors.....

  17. #17
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    u can do one thing...u can have some textfield or hidden field.assign the value to this and retreive thru jsp.
    Ramya:cool:

  18. #18
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Question

    Quote Originally Posted by RamyaSivakanth View Post
    u can do one thing...u can have some textfield or hidden field.assign the value to this and retreive thru jsp.
    do you mean that to assign the value to the field which is in a form and then retrieving it on another page through request.getParameter

  19. #19
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    yes u can do as u said and simplfy in receiving the value without going to other page
    Ramya:cool:

  20. #20
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. help needed
    By amarchandar in forum New To Java
    Replies: 1
    Last Post: 02-18-2009, 12:38 PM
  2. help needed
    By amarchandar in forum New To Java
    Replies: 3
    Last Post: 02-17-2009, 02:59 PM
  3. help needed!!! :S
    By mark-mlt in forum Networking
    Replies: 1
    Last Post: 04-14-2008, 10:27 AM
  4. Help needed.
    By necro-1000 in forum AWT / Swing
    Replies: 2
    Last Post: 01-12-2008, 12:37 PM
  5. Help Needed
    By pks in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 01:07 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
  •