Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:11+00:00 2026-06-12T09:24:11+00:00

(Possibly) simple jQuery question here. I’m using jQuery UI Dialog, and am putting a

  • 0

(Possibly) simple jQuery question here. I’m using jQuery UI Dialog, and am putting a confirm into place. Basically, when a user selects a certain option (in combination with other circumstances), I want to be able to send them either back to the last select they had, or if I can’t do that, a default one.

There is no “selected” attribute to the option either, which would have been my go-to example. Is there a way to do this?

Here is the js:

alert('hey')
if (document.frm.notNull.checked == true) {
    // This is where it ends!
    if ($('input[name=valueTextField]').length > 1) {
        $('#dialog p').empty();
        $('#dialog p').html("You're going to lose your stuff if you do this. You sure you want to?");
        $('#dialog').dialog({
            autoOpen: true,
            width: 600,
            modal: true,
            buttons: {
                "<spring:message code='dialogBox.cancelConfirmation.YES'/>": function() {
                    $(this).dialog("close");
                    $("#bottom").css('visibility', 'visible');
                    $('.edit-new').css('visibility', 'hidden');
                    $('.edit-trash').css('visibility', 'hidden');
                    // if table has more than one row, delete the rest.
                    deleteExtraRows('valueTable');
                    return true;

                },
                "<spring:message code='dialogBox.cancelConfirmation.NO'/>": function() {
                    $(this).dialog("close");

                    // Need to revert the user back to where they came from here.
                    $('#control[value=1]').attr('selected', true);
                    // return false;
                }
            }
        });
    } else {
        $("#bottom").css('visibility', 'visible');
        $('.edit-new').css('visibility', 'hidden');
        $('.edit-trash').css('visibility', 'hidden');
        // if table has more than one row, delete the rest.
        deleteExtraRows('valueTable');
        return true;

     }
 }​

And this is HTML (being rendered dynamically):

<div class="lbl">
    <label>Control</label>
</div>
<select style="margin:0 0 0 8px; left:15px; position:relative;" name="control"
id="control" onChange="checkTableVisibility();">
    <option value=1>Check Box</option>
    <option value=0>Dropdown Menu</option>
    <option value=3>Radio Button</option>
    <option value=2 selected="selected">Text Box</option>
</select>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:24:12+00:00Added an answer on June 12, 2026 at 9:24 am

    Here is the sample code. Hope this might help you

    ##### Jquery Part #####
    <script>
    $(document).ready(function(){
     var dropdownControl =$("#control");
     var selectedValue = dropdownControl.val(); 
     dropdownControl.change(function(){
      var dropItem = $(this);
      $('#dialog').dialog({
      autoOpen: true,
          width: 600,
          modal: true,
          buttons: {
              'Ok': function(){
                      selectedValue = dropItem.val();
                      $(this).dialog("close");
                   },
                   'Cancel' : function(){
                         dropdownControl.val(selectedValue);
                         $(this).dialog("close");
                   } 
                  }
      });
      });
    });
    </script>
    
    
     #### HTML #####
    <body>
     <div>
        <select style="margin:0 0 0 8px; left:15px; position:relative;" name="control" id="control">
         <option value=1>Check Box</option>
         <option value=0>Dropdown Menu</option>
         <option value=3>Radio Button</option>
         <option value=2 selected="selected">Text Box</option>
        </select>
     </div>
     <div id="dialog" style="display:none;">
       Do you want to change value ?
     </div>
    </body>
    

    I wish you could have put more code. I have added some code which might help in you case. Please go through my changes and comments associate with it. I am wrapping you whole code into jQuery ready function. Please let me know if it worked.

     $(document).ready(function(){
      var dropdownControl =$("#control");
      var previousValue = dropdownControl.val(); 
      /// Please add above line of code on your jQuery onload section. So that previous value get set, for the first time, whenever dom gets load. so that you can use it for later cases
    alert('hey')
    if (document.frm.notNull.checked == true) {
      // This is where it ends!
      if ($('input[name=valueTextField]').length > 1) {
          $('#dialog p').empty();
          $('#dialog p').html("You're going to lose your stuff if you do this. You sure    you want to?");
        $('#dialog').dialog({
            autoOpen: true,
            width: 600,
            modal: true,
            buttons: {
                "<spring:message code='dialogBox.cancelConfirmation.YES'/>": function() {
                    $(this).dialog("close");
                    $("#bottom").css('visibility', 'visible');
                    $('.edit-new').css('visibility', 'hidden');
                    $('.edit-trash').css('visibility', 'hidden');
                    previousValue = dropdownControl.val();
                    // please reset previousValue with the new one that you approved to change so that next time when dropdown changes it value it could use it
                    // if table has more than one row, delete the rest.
                    deleteExtraRows('valueTable');
                    return true;
    
                },
                "<spring:message code='dialogBox.cancelConfirmation.NO'/>": function() {
                    $(this).dialog("close");
    
                    // Need to revert the user back to where they came from here.
                    $('#control[value=1]').attr('selected', true);
                     dropdownControl.val(previousValue);
                    // Please replace dropdown value with the old one if you want to revert changes.
                    // return false;
                }
            }
        });
    } else {
        $("#bottom").css('visibility', 'visible');
        $('.edit-new').css('visibility', 'hidden');
        $('.edit-trash').css('visibility', 'hidden');
        // if table has more than one row, delete the rest.
        deleteExtraRows('valueTable');
        return true;
    
     }
    }​ 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A small question hopefully with a simple answer, I am using jQuery draggable and
Here's a dead-simple webpage that leaks memory in IE8 using jQuery (I detect memory
Actually, I have already asked this question here: jQuery simple Data Pass HTML I
This is a really simple question. Is it possible for jQuery to get an
I am new to JQuery I am writing a simple data validation using JQuery.
I'm using jQuery Cycle plugin to create a very simple slideshow. Below the script:
Hopefully this is a simple question for a jQuery newbee. Is it possible to
(Hopefully) Simple question: Is it possible to make the jQuery UI Datepicker draggable? If
We are developing JQuery Mobile app using RC1 + ASP.NET MVC3. My question is:
I'm using jQTouch to build a simple mobile app with an html/js/jquery form that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.