Results 1 to 3 of 3

Thread: add new input feild javascript button not working

  1. #1
    Join Date
    Nov 2011
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default add new input feild javascript button not working

    Hi found some scrip that allows to add more input feilds in you press the + sign but it doesnt appear to be working. can anyone see what is wrong with it please?

    Code:
    <script language="javascript">
    	function fncCreateElement(){
    		
    	   var mySpan = document.getElementById('mySpan');
    
    	   var myLine = document.getElementById('hdnLine');
    	   myLine.value++;
    
    	   // Create input text
    	   var myElement1 = document.createElement('input');
    	   myElement1.setAttribute('type',"text");
    	   myElement1.setAttribute('name',"txtGalleryName"+myLine.value);
    	   myElement1.setAttribute('id',"txt"+myLine.value);
    	   mySpan.appendChild(myElement1);	
    	   
    	   // Create input file
    	   var myElement2 = document.createElement('input');
    	   myElement2.setAttribute('type',"file");
    	   myElement2.setAttribute('name',"fileUpload"+myLine.value);
    	   myElement2.setAttribute('id',"fil"+myLine.value);
    	   mySpan.appendChild(myElement2);	
    		
           // Create <br>
    	   var myElement3 = document.createElement('<br>');
    	   myElement3.setAttribute('id',"br"+myLine.value);
    	   mySpan.appendChild(myElement3);
    	}
    
    	function fncDeleteElement(){
    
    		var mySpan = document.getElementById('mySpan');
    
    		var myLine = document.getElementById('hdnLine');
    		
    		if(myLine.value > 1 )
    		{
    
    			// Remove input text
    			var deleteFile = document.getElementById("txt"+myLine.value);
    			mySpan.removeChild(deleteFile);
    
    			// Remove input file
    			var deleteFile = document.getElementById("fil"+myLine.value);
    			mySpan.removeChild(deleteFile);
    
    			// Remove <br>
    			var deleteBr = document.getElementById("br"+myLine.value);
    			mySpan.removeChild(deleteBr);
    
    			myLine.value--;
    		}
    	}
    </script>
    Code:
    <form action="php_multiple_upload5.php" method="post" name="form1" enctype="multipart/form-data">
    		<input type="text" name="txtGalleryName1"><input type="file" name="fileUpload1">
    		<input name="btnCreate" type="button" value="+" onClick="JavaScript:fncCreateElement();">
    		<input name="btnDelete" type="button" value="-" onClick="JavaScript:fncDeleteElement();"><br>	
    		<span id="mySpan"></span>
    		<input name="hdnLine" type="hidden" value="1">
    		<input name="btnSubmit" type="submit" value="Submit">
    	</form>
    thanks in advance

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    How did you reach this level of coding without learning to use the error console?

    document.getElementById expects an ID.

  3. #3
    Join Date
    Nov 2011
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    its code of the internet

Similar Threads

  1. Using 3D Depressible Button with the input tag
    By mjsingh in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 04-14-2013, 11:12 PM
  2. Anonymous Feild name and Table name
    By letom in forum MySQL and other databases
    Replies: 0
    Last Post: 03-14-2013, 04:14 PM
  3. Javascript not working for liquid css button
    By arc_85 in forum JavaScript
    Replies: 1
    Last Post: 10-20-2010, 11:59 AM
  4. Replies: 0
    Last Post: 10-20-2010, 11:02 AM
  5. form feild value's
    By geoffb in forum HTML
    Replies: 4
    Last Post: 10-19-2006, 01:48 PM

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
  •