PDA

View Full Version : Modifying the name of a previously added input box (IE problem)


pinkshiro
07-07-2008, 01:09 AM
Hello World! I has problem :/

I'm adding a set of radio buttons onto the stage, and applying the name of each input in two different ways - one for IE, and one for everything else :) See below:

if(isIE){//IE workaround
lastName_Input0=document.createElement('<input name="p2_4_migrating'+total+'[]>');
lastName_Input0.type = "radio";
lastName_Input0.value = "defaultRadioButton";
lastName_Input0.style.display = "none";
lastName_Input0.checked = true;
lastName_Input0.id = inputID1;

lastName_Input=document.createElement('<input name="p2_4_migrating'+total+'[]>');
lastName_Input.type = "radio";
lastName_Input.value = "Yes";
lastName_Input.id = inputID2;

lastName_Input1=document.createElement('<input name="p2_4_migrating'+total+'[]>');
lastName_Input1.type = "radio";
lastName_Input1.value = "No";
lastName_Input1.id = inputID3;

lastName_Input1.checked = true;

} else {
var lastName_Input0 = document.createElement('input');
lastName_Input0.type = "radio";
lastName_Input0.checked = true;
lastName_Input0.name = "p2_4_migrating"+total+"[]";
lastName_Input0.value = "defaultRadioButton";
lastName_Input0.style.display = "none";
lastName_Input0.id = inputID1;

var lastName_Input = document.createElement('input');
lastName_Input.type = "radio";
lastName_Input.name = "p2_4_migrating"+total+"[]";
lastName_Input.value = "Yes";
lastName_Input.id = inputID2;

var lastName_Input1 = document.createElement('input');
lastName_Input1.type = "radio";
lastName_Input1.name = "p2_4_migrating"+total+"[]";
lastName_Input1.value = "No";
lastName_Input1.id = inputID3;
}

The problem comes when I want to access one of the input boxes added with the code above, and change the name of the input boxes. In Firefox I can just use inputElement.name = "new name";. As you may know, this isn't recognised in IE. How do I change the name of added input code if they already exist on the stage which works with internet explorer?

Do I need to delete the existing ones and replace them with new radio fields with the new names??? Sounds like I could run into issues here, because what if a radio button has already been checked. I would need to keep a record of whether it was checked. Sounds like a lot of work when all I want to do is update their names!

fside
07-07-2008, 01:58 AM
If you didn't have to use, name, you could add any property you wished and use that, instead. Or if you need fixed names, then a vector, a 'hash table', where you match the fixed, name, to whatever changeable variable name you want at that moment?

Or if there's a need to show different labels in different contexts on screen, if one can't reset a label at runtime, maybe don't use one in the first place but attach a span or div, that is positioned where the label would be, and with an id that you could reference in order to alter the innerHTML?

pinkshiro
07-07-2008, 02:19 AM
I have to assign a name to an input, for it to register as a POST when the user hits submit.

Here's my scenario:

User visits page. Page initially has fields for one child -name, age e.t.c plus a set of radio fields.

There is a button which allows users to add a new set of fields to the page for a new child. When doing this, the names for the input fields type radio myst be unique, but in order. Ie name="radio1", name="radio2".

The extra functionality is the ability to remove sets of fields. Say, they have added too many children onto the form and now remove child 2. Child 3 and 4 must have their input names updated, so child 3's name becomes "radio2" and child 4's name becomes "radio 3"

fside
07-07-2008, 03:37 AM
So the name is necessary for Submit? It just doesn't seem that the name itself is important, other than for 'positioning'. If you are using the integers as a sort order, then you'll have gaps, but 3 is still 'higher up than' 4, etc. Or have a serverside function that just maps the order from one with gaps to one without? Perhaps you could just read the value regardless of name? Again, I don't know the details of what you're trying to do.

pinkshiro
07-07-2008, 04:08 AM
I think I may have over complicated my question :)

The name itself is important, because on other pages I am specifically looking for incrementing values in the serialized $_POST data.

Here's my question, in simplified format :) How can I rename an input field in an IE friendly manner. For example:

change <input id="randomID" name="randomname2"> to <input id="randomID" name="randomname1">

Keep in mind that randomID.name = "randomname1"; will not work in IE.

pinkshiro
07-07-2008, 11:42 AM
Any help would be appreciated...this fundamental problem must have come up before...renaming an input in IE....

rnd me
07-07-2008, 11:49 AM
if "document.createElement('<input name="p2_4_migrating'+total+'[]>');" works, its by accident.

pinkshiro
07-07-2008, 08:36 PM
hrm, true, but it's the only way of setting the "name" of an input for IE....thus far...

rnd me
07-07-2008, 09:37 PM
tested in IE7:

if(isIE){//IE workaround
lastName_Input0=document.createElement('input');
lastName_Input0.Name='p2_4_migrating'+total+'[]';
lastName_Input0.type = "radio";
lastName_Input0.value = "defaultRadioButton";
lastName_Input0.style.display = "none"
...

pinkshiro
07-07-2008, 10:30 PM
Also using IE7, and this didn't work :/ The radio buttons appear, but are unselectable...if I click on any of the radios, they don't appear checked...:eek:

rnd me
07-07-2008, 10:45 PM
Also using IE7, and this didn't work :/ The radio buttons appear, but are unselectable...if I click on any of the radios, they don't appear checked...:eek:

then the names are somehow wrong.
was this a problem before?
the answer to your post is to capitalize the Name property,
but you are still stuck?


if you could post the whole code, i wouldn't have to guess what total and inputID2 are. i am just as stuck as you are without knowing what's going on.

i don't mind helping, but i feel like i am disarming a bomb with a blindfold on...

so let's see where we're at.