0

I've got 2 fields. One is a h:selectOneMenu with a list of places. the other is a h:inputText.

What i'm trying to do is, if the user selects place on the selectOneMenu, and clicks on search, it's gonna search for that place. If he selects a place on the selectOneMenu and still types someplace else on the inputText and clicks on search, it's gonna search for the place that was written and not the selected one.

So, it would be awesome if the user types anything on the inputtext, it would disable the selectOneMenu, and if he clear the field, it would be enabled again. I tried with javascript on event

onchange="if (this.value !='') document.getElementById('placeSelectOneMenu').disabled='true'"

but it didn't work. What can I do? Any ideas?

It only works when I click on search, than it reRender the field correctly. What I want is reRender dynamically.

1
  • "reRender" is a RichFaces 3.x specific attribute name. Are you using RichFaces 3.x? It's not a JavaScript specific term or something. Please use terms with care as abuse/misconception can lead to confusion. Commented May 27, 2011 at 19:56

1 Answer 1

2

The element ID needs to be the ID of the generated HTML element ID, not the JSF component ID. JavaScript has totally no notion of the server side JSF code. All it can see and access is just the HTML DOM tree as generated by JSF. Open the page in the browser, rightclick it and choose View Source. The generated HTML of a <h:selectOneMenu id="placeSelectOneMenu"> should look like this

<select id="someFormId:placeSelectOneMenu">

(where someFormId is the ID of the parent <h:form>)

In this case, you need to get it as follows instead

document.getElementById('someFormId:placeSelectOneMenu')

But since altering the HTML input elements on the client side without notifying the JSF on the server side can lead to unexpected behaviours (if you enable it on the client side by pure JS, then it won't be magically enabled on the server side as well and JSF would not process the submitted value of a field which was initially disabled) and that you're using RichFaces, I'd suggest to go for a pure JSF approach, for example with RichFaces 3.x's <a4j:support> tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.