• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enabling a selectList via javascript does not work

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have been able to disable a selectList via an onklick (spelling onklick wrong on purpose, javaranch seems to be unable to parse it here) event of a radio button. However, my javascript method which should also enable the selectList does NOT work. Once this list is disabled, I cannot re-enable it via javascript.

In the radio button, I have the following onklick event:


These onklicks call this javascript


When 'true' is passed to disable the drop down, it works. When 'false' is passed to the javascript method to enable the drop down, it does not work. I see from the alert message the 'false' is received. Then the second alert returns 'true' since that is the current state of the select box. The last alert, I would assume would return false, since that is what it was just set to, but it returns a 'true', and the box does stay disabled.

Can you only disable things in javascript and not enable them?
Thanks,
Kim
 
Sheriff
Posts: 67746
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

Originally posted by Kim Kantola:
spelling onklick wrong on purpose, javaranch seems to be unable to parse it here

If you are working in HTML, you should have a good working knowledge of HTML Entities. With them, you can easily defeat the posting filters: onclick onclick onclick.

document.form1._selectedUnit.disabled=enabled;


Are you 100% certain that document.form1._selectedUnit is correctly referencing the element? In any case, that's a really old-fashioned way of doing things. You should be assigning an id to the element and using document.getElementById() to reference the element.

Make that change to eliminate that as a source of error and if you're still having difficulties post back and we'll pursue it further.
[ August 04, 2008: Message edited by: Bear Bibeault ]
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess there is a difference between being able to get by the onclick. filters and having the patience to!

I had previously been using document.getElementById(), and then switched to using the control name specifically (_selectedUnit) to try to make things simpler and rule out the fact that maybe I wasn't operating on the correct element, so that can rule out that problem.

I ended up getting by the problem by adding the javascript right to the onclick call, and now it works, not sure why. Here is what I have now:


This works. But doing this inside a javascript function as I showed in my previous post did not. I don't understand why. I also tried defining a javascript boolean instead of setting it to the string value of false and that didn't work either. I am fine now that i have it working but am still curious if anyone knows any reason why that might have not worked.
[ August 04, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
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

Originally posted by Kim Kantola:
I had previously been using document.getElementById(), and then switched to using the control name specifically (_selectedUnit) to try to make things simpler and rule out the fact that maybe I wasn't operating on the correct element, so that can rule out that problem.

You've clearly gone in the wrong direction. Fetching the element by id is exact. The document.form mechanism is fragile and should be avoided.

but am still curious if anyone knows any reason why that might have not worked.

Well, since we don't have access to that code, who can say?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Eric
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Eric. Using false instead of 'false' did the trick.
Going to brush up on javascript . . .
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Wanted to add one more note to this as it may be a help to someone searching on this topic.
I was having trouble with the document.getElementById() call for my radio button element because struts <html:radio tag does not support having an id defined.
I found that the javascript worked if I used to replace

then my javascript worked, however, this did NOT work :
 
Bear Bibeault
Sheriff
Posts: 67746
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
Well yeah, if Struts won't let you put an id on an element (big :roll: ) then you can't use an id.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic