Help with form layout on window resize

Discussion in 'CSS' started by rinoa_26, Aug 31, 2010.

  1. #1
    Hi i need to layout my form so that when maximized it will display like this

    FirstName LastName Phone
    <FirstName Input box> <LastName Inputbox> <Phoneinputbox> <button>


    and when minimized it will display like this

    Firstname <inputbox>
    Lastname <inputbox>
    Phone <inputbox>
    <button>


    how should i do this in css? thanks in advance
     
    rinoa_26, Aug 31, 2010 IP
  2. Piotr Aszoff

    Piotr Aszoff Active Member

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    53
    #2
    Mayby, two forms wchich are submiting same things:

    <div id="form1">
    <a href="#" onclick="change(1)">max</a>
    <form>
    	First name:	<input type=text /><br />
    	Last name: <input type=text /><br />
    	Phone: <input type=text /><br />
    	<button>click me</button>
    	
    </form>
    </div>
    
    <div id="form2">
    <a href="#" onclick="change(2)">min</a>
    <form>
    	First name: Last name: Phone:<br />
    	<input type=text />
    	<input type=text />
    	<input type=text />
    	<button>clik me</button>
    </form>
    </div>
    Code (markup):
    And in the css file:

    #form1{
    	display:block;
    }
    
    #form2{
    	display:none;
    }
    Code (markup):
    And finally, some javascript:
    <script>
    
    	function change(i){
    		form1=document.getElementById("form1");
    		form2=document.getElementById("form2");
    		if(i==1){
    		form1.style.display="none";
    		form2.style.display="block";
    		}
    		else{
    		form1.style.display="block";
    		form2.style.display="none";
    		}
    	}
     </script>
    Code (markup):

    Hope it helps, Peter

    P.S. Almost forgot, you can also use one form and try to change its innerHTML value.
     
    Piotr Aszoff, Sep 1, 2010 IP
  3. Aven

    Aven Peon

    Messages:
    335
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Remember that
    display: block;
    Code (markup):
    is what places an input to be on a line on its own, and the DEFAULT IS
    display: block;
    Code (markup):
    so if you ever want it in the same line, change it to
    display: inline;
    Code (markup):
     
    Aven, Sep 1, 2010 IP
  4. dellgx270

    dellgx270 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
     
    dellgx270, Sep 1, 2010 IP
  5. rinoa_26

    rinoa_26 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,
    Thanks Peter and all who replied, but
    I want it the it will automaticall change layout when the browser window is maximize and/or minimize not when a link was click.
    anyone got an idea how this can be done
     
    rinoa_26, Sep 3, 2010 IP
  6. Piotr Aszoff

    Piotr Aszoff Active Member

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    53
    #6
    Maybe something like this:

    var i=1;
    $(document).ready(
    	function()
    	{
    		$(window).resize(function() {
    			if(i%2==1){
    			$("#form1").html("First name:<input type=text /><br />Last name: <input type=text /><br />Phone: <input type=text /><br /><button>click me</button>");
    			i++;
    			}
    			else{
    			$("#form1").html("First name:<input type=text />Last name: <input type=text />Phone: <input type=text /><button>click me</button>");
    			i++;
    			}
    		});
    })
    Code (markup):
    But the problem is when the window is minimized at first (it works vice versa than).

    Hope it helps, Peter
     
    Piotr Aszoff, Sep 4, 2010 IP
  7. dellgx270

    dellgx270 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    test. sorry
     
    dellgx270, Sep 19, 2010 IP