How to make links open/close a form

Discussion in 'JavaScript' started by Scriptona, Mar 17, 2007.

  1. #1
    Hello,

    i need to make 2 links and every one of them open different form

    so i need some thing like this

    Link 1 - Link 2

    Form

    when i click on "Link 1" it opens the form

    when i click on "Link 3" it opens another form in the same place of form 1

    how can i do this ?

    i believe it's some kind of java script
     
    Scriptona, Mar 17, 2007 IP
  2. maonnie

    maonnie Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Use, window.open(url, "myforms", options); - replace url & options with something sensible.
     
    maonnie, Mar 17, 2007 IP
  3. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Try this code. I hope this is what you want.
    <html>
    <head>
    <script type="text/javascript">
    <!--
    var arElems = new Array('id1', 'id2', 'id3');
    function toggle(id){
    	for(i in arElems){
    		el = document.getElementById(arElems[i]);
    		if(id == arElems[i])el.style.display = '';
    		else el.style.display = 'none';
    	}
    }
    //-->
    </script>
    </head>
    
    <body>
    <a href="javascript:toggle('id1');">Form 1</a> :: <a href="javascript:toggle('id2');">Form 2</a> :: <a href="javascript:toggle('id3');">Form 3</a>
    <div id='id1' style="display:;">
    <form name='form1'>
    <span>First Form</span><br/>
    <input type="text" name="txt_1_1"/><br/>
    <input type="text" name="txt_1_2"/><br/>
    <input type="submit" value="Submit Form 1"/>
    </form>
    </div>
    <div id='id2' style="display:none;">
    <form name='form2'>
    <span>Second Form</span><br/>
    <input type="text" name="txt_2_1"/><br/>
    <textarea></textarea><br/>
    <input type="submit" value="Submit Form 2"/>
    </form>
    </div>
    <div id='id3' style="display:none;">
    <form name='form3'>
    <span>Third Form</span><br/>
    <input type="text" name="txt_3_1"/><br/>
    <input type="text" name="txt_3_2"/><br/>
    <input type="text" name="txt_3_3"/><br/>
    <input type="submit" value="Submit Form 3"/>
    </form>
    </div>
    </body>
    </html>
    
    HTML:
     
    Aragorn, Mar 18, 2007 IP