Jagadeesh M
asked on
struts html:select dropdown
Hi -
I'm using Struts.
I've a drop down for displaying the status of the property and i need to add a confirm dialog box for this -
Here is a sample code snippet -
<html:select styleClass="formTextField" property="propStatusCd" tabindex="1" onchange="return confirmPropStatusChange(); " >
<html:option value="">-- Select --</html:option>
<html:options collection="<%=LookupTypeD ropdownUti ls.LOOKUPE NM_Propert yStatusLoo kupType%>"
property="typeIdCode" labelProperty="typeName" />
</html:select>
And here is my javascript -
<SCRIPT language="JavaScript">
<!--
function confirmPropStatusChange() {
if (confirm("!")) {
return true;
} else {
return false;
}
}
//-->
</SCRIPT>
Now when i change the dropdown value, the confirm dialog box is being prompted but irrespective of whether i select "OK" or "CANCEL" the drop down value is getting changed.
But it should be something like - When i select "OK" the new value should be retained but when i select "CANCEL" the old value should be retained.
Please advice.
Thank You-
I'm using Struts.
I've a drop down for displaying the status of the property and i need to add a confirm dialog box for this -
Here is a sample code snippet -
<html:select styleClass="formTextField"
<html:option value="">-- Select --</html:option>
<html:options collection="<%=LookupTypeD
property="typeIdCode" labelProperty="typeName" />
</html:select>
And here is my javascript -
<SCRIPT language="JavaScript">
<!--
function confirmPropStatusChange() {
if (confirm("!")) {
return true;
} else {
return false;
}
}
//-->
</SCRIPT>
Now when i change the dropdown value, the confirm dialog box is being prompted but irrespective of whether i select "OK" or "CANCEL" the drop down value is getting changed.
But it should be something like - When i select "OK" the new value should be retained but when i select "CANCEL" the old value should be retained.
Please advice.
Thank You-
It will because you are calling JS function onchange i.e. value is already changed. You need to know what was the value before and if user says cancel reset dropdown value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How do i do that!! Any sample snippets!!
ASKER
but struts html:select tag does not support id tag
ASKER
I think i got the answer ---- here is my solution
<SCRIPT>
// Confirm Property Status Change
function confirmPropStatusChange(n) {
if(! confirm ('Do you really want to change Property Status!!')){
n.value = '<%=pf.getPropStatusCd()%> ' ;
}
}
</SCRIPT>
<html:select styleClass="formTextField" property="propStatusCd" tabindex="1" onchange = "confirmPropStatusChange(t his)" >
<html:option value="">-- Select --</html:option>
<html:options collection="<%=LookupTypeD ropdownUti ls.LOOKUPE NM_Propert yStatusLoo kupType%>"
property="typeIdCode" labelProperty="typeName" />
</html:select>
Thank You.
<SCRIPT>
// Confirm Property Status Change
function confirmPropStatusChange(n)
if(! confirm ('Do you really want to change Property Status!!')){
n.value = '<%=pf.getPropStatusCd()%>
}
}
</SCRIPT>
<html:select styleClass="formTextField"
<html:option value="">-- Select --</html:option>
<html:options collection="<%=LookupTypeD
property="typeIdCode" labelProperty="typeName" />
</html:select>
Thank You.
for struts you don't need to specify id. property should be fine.
If that does not work then use styleId instead of id.
If that does not work then use styleId instead of id.
If you have found your own solution then you can ask for point refund. If any of my suggestion helped you then you can give me points.
Thanks
Thanks
Actually @jagadeesh_motamarri's solution is based on what I have suggested as a possible solution. I gave him an example if you compare that is exactly what he did other than assigning java value. Where in my solution I am using Javascript value.
I should get points.
I should get points.
raj3060,
Thanks for your comment. I only quickly looked over the comments because of your and the Asker's last comments. You should not have been so quick to "give away" the points. ;)
jagadeesh_motamarri,
As I look over this closer it seems to me your solution used raj3060's comment and suggestion at http:#19566424. If you feel your solution was independent of that comment or any help raj3060 provided then please post and explain. Since it seems that raj3060's comment, at the very least, was a big contribution to the solution I will change my recommendation.
Changed recommendation: Accept raj3060 {http:#19566424}
If there are no objections then this will be closed in a couple of days.
b0lsc0tt
EE Cleanup Volunteer
Thanks for your comment. I only quickly looked over the comments because of your and the Asker's last comments. You should not have been so quick to "give away" the points. ;)
jagadeesh_motamarri,
As I look over this closer it seems to me your solution used raj3060's comment and suggestion at http:#19566424. If you feel your solution was independent of that comment or any help raj3060 provided then please post and explain. Since it seems that raj3060's comment, at the very least, was a big contribution to the solution I will change my recommendation.
Changed recommendation: Accept raj3060 {http:#19566424}
If there are no objections then this will be closed in a couple of days.
b0lsc0tt
EE Cleanup Volunteer