SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing names of input fields

    Okay, I'm trying to create a form out of an input box in a hidden span. The input box is named FNAME_ADD_ and in the function to show the input box, I'm changing the name based on the folder number (eg. FNAME_ADD_1, FNAME_ADD_2, etc). The problem I've encountered is that it changes the name of the hidden text box as well as the new one that it is showing (when the input box is shown, it adds on to the innerHTML of another div, thus allowing me to build up text boxes).

    Is there any way I can show the input box, and change its name without changing the previous instance?

    Here is the code I'm using:
    Code:
    	function AddTextBoxes(){
    		FolderNum++;
    		alert(TextBoxes.innerHTML);
    		if(FolderNum > 10){
    			alert("You cannot enter more than 10 folders!");
    			return;
    		}
    		
    		EditButton_ADD_.href = "Javascript:ShowPlainText(" + FolderNum + ", null, \"ADD_\")";
    
    		FNAME_ADD_.id = "FNAME_ADD_"  +  FolderNum;
    		FNAME_ADD_.name = "FNAME_ADD_"  +  FolderNum;
    		sFNAME_ADD_.id = "sFNAME_ADD_"  +  FolderNum;
    		EditButton_ADD_.id = "EditButton_ADD_" + FolderNum;
    		DeleteButton_ADD_.id = "DeleteButton_ADD_" + FolderNum;
    		NewTextBoxes.innerHTML += TextBoxes.innerHTML;
    		alert(NewTextBoxes.innerHTML);
    	}
    This only needs to work in IE5+.

    Thanks,
    Joe Fiorini
    Last edited by jfiorini; May 29, 2002 at 13:02.
    -Joe

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not exactly sure what your trying to do, but it seems your looking in completely the wrong direction.

    createElement

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question createElement is cool, but still having problems...

    Hey, thanks for that link. I used the new code, and it seems to work well. I have another question though.

    I'm using this code to add textboxes to a SPAN element. The user can click on a button up to 10 times to add text boxes, and when they are finished entering their data, they submit the form. The form submits to an ASP script that will add the data to a DB. The problem comes when trying to access the information through Request.Form(whatever). The javascript code that I'm using doesn't seem to generate the name attribute of the input box (at least, it doesn't show up in the innerHTML of the span after I add it). Here is the code I am using:

    Code:
    	function AddTextBoxes(){
    		FolderNum++;
    
    		if(FolderNum > 10){
    			alert("You cannot enter more than 10 folders!");
    			return;
    		}
    		
    		//First, we create our elements
    		NEW_TABLE = document.createElement("table");
    		NEW_TR = document.createElement("tr");
    		NEW_TD1 = document.createElement("td");
    		sNEW_ADD = document.createElement("span");
    		NEW_ADD = document.createElement("input");
    		NEW_TD2 = document.createElement("td");
    		NEW_EditButton = document.createElement("a");
    		sNEW_DeleteButton = document.createElement("span");
    		NEW_DeleteButton = document.createElement("a");
    
    		//Now setup all the IDs and names
    		sNEW_ADD.id = "sFNAME_ADD_"  +  FolderNum;
    		NEW_ADD.id = "FNAME_ADD_"  +  FolderNum;
    		NEW_EditButton.id = "EditButton_ADD_" + FolderNum;
    		NEW_DeleteButton.id = "DeleteButton_ADD_" + FolderNum;
    		NEW_ADD.name = "FNAME_ADD_"  +  FolderNum;			//THIS DOES NOT WORK!!!
    		
    		//Set any other attributes that are required
    		sNEW_ADD.className = "black10b";
    		NEW_ADD.className = "editfolder";
    		NEW_TD2.className = "black10b";
    		NEW_EditButton.innerText = "Done";
    		NEW_EditButton.href = "Javascript:ShowPlainText(" + FolderNum + ", null, \"ADD_\")";
    		sNEW_DeleteButton.className = "hidden";
    		
    		//Now we append our children, starting from the furthest point inside, to the outside
    		sNEW_DeleteButton.appendChild(NEW_DeleteButton);
    		NEW_TD2.appendChild(NEW_EditButton);
    		NEW_TD2.appendChild(sNEW_DeleteButton);
    		NEW_TD1.appendChild(sNEW_ADD);
    		NEW_TD1.appendChild(NEW_ADD);
    		NEW_TR.appendChild(NEW_TD1);
    		NEW_TR.appendChild(NEW_TD2);
    		NEW_TABLE.appendChild(NEW_TR);
    		NewTextBoxes.appendChild(NEW_TABLE);
    		alert(NewTextBoxes.innerHTML);
    		NewTextBoxes.innerHTML = NewTextBoxes.innerHTML;
    
    	}
    Also, anybody who has experience using createElement, is this the right way to go about using it? What would be a better way?

    Thanks!
    -Joe

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <sigh>

    And I've once again managed to answer my own question...

    The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.

    MSDN Library - NAME attribute
    According to the documentation on the createElement method (see link two posts above), in order to create an input element with a name attribute, you must add it when the element is created, for example:

    Code:
    NEW_ADD = document.createElement("input name=\"FNAME_ADD_1\"");
    And that's it! My code is almost complete!

    Later,
    Joe
    -Joe


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
  •