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 461821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:00:47+00:00 2026-05-12T23:00:47+00:00

At the moment, I have this DIV with a registration form centered over the

  • 0

At the moment, I have this DIV with a registration form centered over the page. The contents of the DIV come from an ascx-page. This is done nicely.
Now, if the user tries to fill in a name that’s not unique, an error message is added by some jQuery next to the username field. This breaks the layout of the DIV, since the contents now are wider than they used to be.
So I’ve googled my way into this, but I can’t find a solution for this.

Can anyone help me find a nice way to do this (pseudo HTML/js):

<div id="myCenteredDiv" onChangeContents="resizeToNewSize()">
  <!-- div contents -->
</div>

<script type="text/javascript">
  function resizeToNewSize() {
    $("#myCenteredDiv").animateToSize($("#myCenteredDiv").contentWidth, 
      $("#myCenteredDiv").contentHeight);
  }
</script>

I’m looking for the “onChangeContents” method (and/or event) and the “div.contentWidth” property.

Thanks a lot for helping me out!

update: trying to explain the problem more clearly

Let’s say I have this DIV:

<div id="myDiv">
  <form ...>
    Enter your name: <input id="txtYourName" type="text" name="YourName" value="" />
    <span id="errorYourName"></span>
    <input type="submit" ... />
  </form>
</div>

And let’s say I have this snippet of jQuery:

$(document).ready(function() {
  $("#txtYourName").live("blur", function() {
    if (validateInput($("#txtYourName").val())) {
      $("#errorYourName").html("");
      // entry 1
    } else {
      // entry 2
      $("#errorYourName").html("This name is not valid.");
    }
  });
});

…where validateInput(value) returns true for a valid value.

Well now. The SimpleModal plugin takes the div and places it centered on the page, with a certain width and height it somehow reads off of the contents of the div. So the div isn’t wider than the input box, since the span is empty at the moment.

When the input box loses focus, an error message is put into the span. This then breaks the layout of the div.

I could put code into entry 1 that resizes the div back with an animation to some size when the error message has been cleared, and code into entry 2 that resizes the div to a bigger size so the error message will fit.

But what I’d like best is a way to tell if the contents within the div have changed, and fit the div accordingly, animated and automatically.

Any ideas? Thanks again.

  • 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-05-12T23:00:47+00:00Added an answer on May 12, 2026 at 11:00 pm

    I’ve never used SimpleModal, but from the examples on their site it looks like you can set the container CSS. If you want the height to adjust, try setting the height to auto

    $("#sample").modal({
      containerCss:{
        backgroundColor:"#fff",
        borderColor:"#0063dc",
        height:450,
        padding:0,
        width:830
      }
    });
    

    Although the example doesn’t have it, I’d think you need to add px after the height and width in quotes (e.g. "450px").


    Ok here is another idea. Maybe this is too much, but add a hidden input field:

    <div id="myDiv">
      <form ...>
        Enter your name: <input id="txtYourName" type="text" name="YourName" value="" />
        <span id="errorYourName"></span>
        <input type="submit" ... />
        <input id="updated" type="hidden" />
      </form>
    </div>
    

    then attach a change event which is triggered at the same time you update the error message.

    $(document).ready(function() {
      $("#txtYourName").live("blur", function() {
        if (validateInput($("#txtYourName").val())) {
          $("#errorYourName").html("");
          // entry 1
        } else {
          // entry 2
          $("#errorYourName").html("This name is not valid.");
          $("#updated").trigger('change');
        }
      });
      $("#updated").change(function(){
        // resize the modal window & reposition it
      })
    });
    

    This is untested and it may be going overboard, but I don’t see an update function in SimpleModal.


    Update : Sorry I figured out that blur isn’t supported with live event. So I did some further testing and came up with a working demo. I posted it in this pastebin (ignore the included simpleModal code at the bottom). Here is the essential code

    CSS

    #myDiv { line-Height: 25px; }
    #simplemodal-container { background-color:#444; border:8px solid #777; padding: 12px; }
    .simplemodal-wrap { overflow: hidden !important; }
    .error { color: #f00; display: none; }
    input { float: right; }
    

    HTML

    <div id="myDiv">
      <form>
        What is your name: <input id="txtYourName" type="text" name="YourName" value="" /><br>
        <div id="errorYourName" class="error">This name isn't Arthur.</div>
    
        What is your quest: <input id="txtYourQuest" type="text" name="YourQuest" value="" /><br>
        <div id="errorYourQuest" class="error">This quest must be for the Grail.</div>
    
        What is your favorite color: <input id="txtYourColor" type="text" name="YourColor" value="" /><br>
        <div id="errorYourColor" class="error">Sorry, you must like red or blue.</div>
    
        What is the air speed velocity of an unladen swallow:<br>
        Type:
        <select>
         <option>African</option>
         <option>European</option>
        </select>
        <input id="txtYourGuess" type="text" name="YourGuess" value="" /><br>
        <div id="errorYourGuess" class="error">This guess stinks.</div>
        <hr>
        <input id="submitMe" type="submit" />
      </form>
    </div>
    

    Script

    $(document).ready(function(){
      $("#myDiv").modal({
       containerCss:{
        height: '165px',
        width: '350px'
       }
     })
     $("#txtYourName").focus();
    
     addValidate('#txtYourName','Arthur','#errorYourName');
     addValidate('#txtYourQuest','Grail|grail','#errorYourQuest');
     addValidate('#txtYourColor','red|blue','#errorYourColor');
     addValidate('#txtYourGuess','11|24','#errorYourGuess'); // See http://www.style.org/unladenswallow/ ;)
    
      $("#myDiv form").change(function() {
       // This is called if there are any changes to the form... added here for an example
       // alert('Form change detected');
      });
    })
    
    function addValidate(el,valid,err){
     $(el).blur(function() {
      if ( $(el).val().length > 0 && !$(el).val().match(valid) ) {
       if ($(err).is(':hidden')) {
        $('#simplemodal-container').animate({'height': ($('#simplemodal-container').height() + 25) + 'px'},1000);
        $(err).slideDown(1000);
       }
      } else {
       // entry 2
       if ($(err).is(':visible')) {
        $('#simplemodal-container').animate({'height': ($('#simplemodal-container').height() - 25) + 'px'},1000);
        $(err).slideUp(1000);
       }
      }
     });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

at the moment i have this <div id=beau> <div> <input type=text id=lun name=lun size=24
I have this method at the moment: <% for comment in @critical_process.review.comments %> <div
At the moment I have this code which fires a projectile: Vector3 d =
I have this script at the moment, which changes an image when a thumbnail
This is what I have at the moment. <h2>Information</h2>\n +<p>(.*)<br />|</p> ^ that is
I have two nested loop in XSL like this, at this moment I use
At the moment when i use this, i have to re-launch the app to
At the moment I have a combobox that is populated from the name fields
I have this at the moment: (the list is longer, but this is just
Im working on some html stuff at the moment but have come across a

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.