This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript help

 
purnima arora
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I am new to java and jsp and this is my first project, but facing some issues. As per our project requirements we have to display the check-boxes equal to number of values in the database, and i have to also call a function on onclick event on this checkbox. but i am not able to do so.
[ May 28, 2008: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
UseAMeaningfulSubjectLine

Also, see
EaseUp to find out why adding "urgent", "asap", or in this case "HELP REQUIRED!!" to your message or subject line can actually slow down or halt responses to your question altogether.




Again, welcome to JavaRanch and good luck with your question.
-Ben
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to the JavaScript forum since it is not about Portlets.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i am not able to do so.
Why not? What have you written so far? What isn't working about it?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well I'm sure you can do a query to the database and return some sort of DataSet when the page loads, and then just echo(response.write, whatever) checkbox's out with their values equal to the unique id of each row in the database.

this way when you click, and have some operation you execute on click of a button, you'll have the id of that row id in the value of the checkbox and can operate just fine.

As far as executing a function that will modify the database when you click a checkbox (what I'm assuming your doing) you can use AJAX.

send a request with the ID of the row append to the url with a GET. Then on the server side you can get the ID and do what you wish. Then when the server is done and has wrote something like "DB operation successfull!" then you can get the response in the client side with AJAX.

This way you never have to refresh or anything like that.

Justin
 
purnima arora
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin

Thanks for the quick response but we dont want to update the database by the javascript function.

We want to function to enable other set of checkboxes when this particular checkbox is clicked. so we want to call a javascript function on onclick event for this particular checkbox.

But the problem we are facing is we are not able to call that particular function since the check-boxes are dynamic.
if you can help us out with that.
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Purnima,

Are the checkboxes generated from the business logic or using JSP and javaScript? In either case if you can also add a 'onChange()' javaScript function call to them so that when the values in the checkkboxes are changed a javaScript function is invoked where you can enable or disable the other set of checkboxes. I mentioned 'onChange()' because I think you want to enable or disable the second set of checkboxes based on the value or even a change of value in the first? IS this what you are looking for?

Cheers,
Raj.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you are creating the checkbox's dynamically, set their id attribute, and their onclick attribute and then you can get the element by it's id uniquely.



then just define your disableAll() function...



Hope this helps,

Justin Fox

[ May 29, 2008: Message edited by: Justin Fox ]
[ May 29, 2008: Message edited by: Justin Fox ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better yet, if you put your 'blocks' of checkboxes in forms, you can just disable/enable the forms when the checkbox is clicked, which will automatically disable/enable the checkbox's within that form.

Justin Fox
 
purnima arora
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin

The code that you had given is for dynamically generating checkboxes with javascript and we are dynamically generating those check-boxes with scriplet, that is why we are not able to assign an id to a check-box properly.

With Regards
Purnima
[ June 02, 2008: Message edited by: Bear Bibeault ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, well that's no good.

there's not a method in java for registering a script block from
the server?

I don't use JSP so I'm just trying to help .

Justin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic