Results 1 to 3 of 3

Thread: script to create textboxes

  1. #1
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default script to create textboxes

    im looking for a script that will create a certain number of textboxes according to the value entered into a specific text box.

    i.e. value of 10 entered into a textbox, user clicks next, 10 text boxes are on the next page with labels next to them such as name1, name 2... etc.

    number can range from 1 to 40 maximum.

    cheers.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<title>An XHTML 1.0 Strict standard template</title>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<meta http-equiv="Content-Style-Type" content="text/css" />
    	<style type="text/css">
    
    	</style>
    	<script type="text/javascript">
    		function createTextBoxes(){
    			if(parseInt(document.getElementById('num').value) > 40 || parseInt(document.getElementById('num').value) < 1){
    				alert('invalid number use number between 1 and 40')
    				return;
    			}
    			document.getElementById('inp').style.display = 'none';
    			for(var i = 0; i < parseInt(document.getElementById('num').value); i++){
    				var input = document.createElement('input');
    				var span = document.createElement('span');
    				span.appendChild(document.createTextNode('name '+ i));
    				var br = document.createElement('br');
    				input.type='text';
    				input.name='text'+i;
    				input.id='text'+i;
    				document.getElementById('tb').appendChild(span);
    				document.getElementById('tb').appendChild(input);
    				document.getElementById('tb').appendChild(br);
    			}
    		}
    	</script>
    </head>
    
    <body>
    	<form name="f1">
    		<div id="inp">
    			<label>No of Textbox</label><input type="text" id="num" name='num' /><br/>
    			<input type="button" value="Create Textboxes" onclick="javascript: createTextBoxes();"/>
    		</div>
    		<div id="tb">
    			
    		</div>
    	</form>
    </body>
    </html>
    Check the above code I've done it quickly so haven't done the validation much but the core functionality works correctly.

  3. #3
    Join Date
    Sep 2008
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Dynamic textbox

    Hi There,

    how are you.

    I created a order form using front page 2002.simply using text boxes.
    it worked well.this form is sent to email ,not to database.

    but the problem is ,the form is too long.

    I like to have button where user can click and text box can appear. Instead of having so many text boxes in my order form.

    Thank you .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •