making more textboxes on the same screen appear when a user clicks a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpbeginner
    New Member
    • Jul 2007
    • 4

    making more textboxes on the same screen appear when a user clicks a button

    I asked this question already, but I am not sure why it has been moved to the javascript forum? ARe you telling me that this cannot be done using php?

    Thanks.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Originally posted by phpbeginner
    I asked this question already, but I am not sure why it has been moved to the javascript forum? ARe you telling me that this cannot be done using php?

    Thanks.
    We're telling you that, in the sense that you are asking, no. If you want to do this upon form submission, then it can be done in PHP, however PHP is not a client-side programming language: It is processed ONCE per page load. So, to do this in PHP, you're page would need to be loaded again.

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Didn't see start of thread but this function will create the number of textboxes entered in the totBoxes text box.
      You need to allocate a <div> called "boxes" in HTML.
      Also needed is an onClick() function for your button.

      Code:
      function createTextBoxes()
      {   			
          var boxes = document.getElementById('totBoxes'); 
      	var noBoxes = boxes.value; 		
      	
      	var mydiv = document.getElementById("boxes");
      		
      	var newHTML = '<br>Enter the data<table border="1" cellspacing="10">';
      	newHTML += '<tr><th>Data</th></tr>';	   
          
      	//Create textboxes  		
      	for(var r=0;r<noBoxes;r++)
      	{
      		newHTML += '<tr>';
      		//alert('here');		
      				  	 
      		var box = 'name="box' + r +'"'; 		  		
      		newHTML += '<td>';	
      		newHTML += '<input type="text"'+ box +'/>';
      		newHTML += '</td></tr>';	    
      	}
      	newHTML += '</table>';	
      	mydiv.innerHTML = newHTML;	  		 
      }
      They are laid out in a table. Probably not what your looking for but its a start

      Comment

      Working...