Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set checkbox "checked" when a value in an selectbox changes

 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Form with more rows, which all have the same layout (kind of an Array).

when a value is set in the selectbox, I want to change the checkbox on the same row to "checked".

the checkbox on every row has a unique value, and is defined like the following definition:
<input type="checkbox" name="addspelers" value="row.<%= (i += 1) %>.check"/>


the selectbox is defined like the following definition:
<select name="row.<%= (i += 1) %>.persid" size="1"/>

Now the onchange statement must be added............???
something like.....
<select name="row.<%= (i += 1) %>.persid" onchange="addspelers.checked" />
<option> bla bla blaaaa
</option>

I'm looking for the exact syntax for addspelers.checked , I want to change only the checkbox for the specific row....

Regards,
Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show what you have tried so far and please UseCodeTags.

 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below the code...
I try to set the value of the hidden field "speler.${details.speler.spelernr}" (on row 19) with the onchange in the other fields (row 29 f.e.), but it doesn't change....
The reason I do this, is that the servlet can check if a row is changed or not.
(Earlier I mentioned that I want to change the value of the checkbox, but that isn't necessary anymore.)

regards,
Mark

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, now please isolate the code you are asking about. It'd be best to post an SSCCE, and make sure that there's no server-side markup in the HTML structure that you are trying to traverse. The browsers gets generated HTML, not JSP markup, so that's not relevant.

Essentially, you want to locate the element that receives the event, and backtrack up the DOM to find the <tr> element parent, and then find the appropriate child of that parent. This is almost trivial with jQuery, but a bit of work in raw JavaScript.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is a problem with the browser not behaving the way you expect, looking at the server-side code will make troubleshooting this problem harder than it needs to be.

My suggestion would be to show us the source that the browser is displaying / interpreting. In your browser, select "show source" and copy/paste that into here.
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below the code when I use show source in the webbrowser



the "onchange" (on row 13) code looks fine to me, but the value shows me spaces when I display it in the servlet. (?)

and here is the Servletcode that displays the value:
the values from "kaart, gespeeld, doelpunten" are correct, the way I expect them.

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your onchange method is referring to speler.10 as though this is something that the browser should naturally know about. Unfortunately browsers only know about standard objects from the DOM.

Rewriting your end-result code to use standard elements (and making it more of an SSCCE):

You can see that I added an ID for the hidden field in line 4 - this makes it easy for finding the object in the DOM tree. I then use that ID in the onchange handler in line 7 to get an object that JavaScript knows how to manipulate (which I can then do by setting the value).

By the way - if you use FireFox, you might want to get the WebDeveloper plugin, which gives you a nice error window for your JavaScript (and CSS) errors.
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muchos gracias, It works fine!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic