Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muchos gracias, It works fine!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic