[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

struts html:select dropdown

Posted on 2007-07-25
11
Medium Priority
?
380 Views
Last Modified: 2008-01-09
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="<%=LookupTypeDropdownUtils.LOOKUPENM_PropertyStatusLookupType%>"
        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-
0
Comment
Question by:jagadeesh_motamarri
  • 5
  • 3
9 Comments
 
LVL 11

Expert Comment

by:raj3060
ID: 19566226
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.
0
 
LVL 11

Accepted Solution

by:
raj3060 earned 400 total points
ID: 19566424
Just an example:

<form>
<P><select id='HOW_HEARD' onchange = "wantToChange(this)">
<option value='1'>Online</option>
<option value='2'>TV</option>
<option value='3'>Newspaper</option>
<option value='4'>Friend</option>
<option value='OTH'>Other</option>
</select></P>
<P>
<LABEL id='OTH_LBL'>Other: <input type = 'text' id='OTH_TEXT'/></LABEL>
</P>
<P>
<input type = 'submit' value='Submit' onclick='return checkOtherText();' style='cursor:hand;'/>
</P>
</form>
<SCRIPT>
var valueBefore = document.getElementById('HOW_HEARD').value;

function wantToChange(n){
      var whatToDo = confirm ('Do you really want to change!!');      
      
      if(!whatToDo){
            n.value = valueBefore;
      }
}
</SCRIPT>
0
 
LVL 10

Author Comment

by:jagadeesh_motamarri
ID: 19566427
How do i do that!! Any sample snippets!!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Author Comment

by:jagadeesh_motamarri
ID: 19567811
but struts html:select tag does not support id tag
0
 
LVL 10

Author Comment

by:jagadeesh_motamarri
ID: 19567905
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(this)"  >
                                                <html:option value="">-- Select --</html:option>
                                                      <html:options collection="<%=LookupTypeDropdownUtils.LOOKUPENM_PropertyStatusLookupType%>"
                                                                                            property="typeIdCode" labelProperty="typeName" />
                                                </html:select>


Thank You.
0
 
LVL 11

Expert Comment

by:raj3060
ID: 19568155
for struts you don't need to specify id. property should be fine.
If that does not work then use styleId instead of id.
0
 
LVL 11

Expert Comment

by:raj3060
ID: 19569964
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
0
 
LVL 11

Expert Comment

by:raj3060
ID: 19857168
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.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19862543
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question