Jump to content

[SOLVED] Removing an ID


mikePhp

Recommended Posts

Hiya Guys,

 

I wanted to remove and ID from a <textarea> tag but i am getting a error that the method is not supported.

 

here is was i am putting..

 

function convert2Html() 
{
    var oldID = document.getElementById('elm1');

    if(!oldID) { return; }

    for(i=0; i<oldID.length; i++)
    {
       var newID = oldID[i].setAttribute('id','idRemoved');
    }
}

window.reload();

 

I have also tried this way as well.

 

function convert2Html()
{
   var formTag = document.getElemenetsByTagName('textarea');
   
   if(!formTag) { return; }

   for(i=0; i<formTag.length; i++)
   {
     var idChange = formTag[i].getAttribute('id');
    
      if(idChange != 'elm1')
      {
         continue;
      }
      else
      {
        idChange.setAttribute('id','removeId');
       }
      }
}

 

None of them seem to work, could any one enlighten me, as to what the problem maybe.. Is it My code???

Link to comment
Share on other sites

Can you show how you're invoking these functions (I'm presuming they're functions), and a sample of the HTML they're supposed to be operating on?

 

Well I have a <textarea> tag with and ID in a form......

 

<form name="Name" method="post" action="#">
<textarea name="elm1" wrap="virtual" class="inputTextStyle" id="elm1"><?php echo $variable; ?></textarea>
<input type="button" name="convert" id="submitBtn" onClick="convert2Html();" />
</form>

 

 

Thats how i call the functions, and also the JS is within the same page, i haven't given the JS its own page and then included it

 

Hope you can help

Link to comment
Share on other sites

Okay, try something like this:

<script type="text/javascript">
   window.onload = function()
   {
      var submitBtn = document.getElementById("submitBtn");
      var elm1 = document.getElementById("elm1");

      submitBtn.onclick = function()
      {
         elm1.setAttribute("id", "idRemoved");
      }
   }
</script>

.
.
.

<form name="Name" method="post" action="#">
<textarea name="elm1" wrap="virtual" class="inputTextStyle" id="elm1"><?php echo $variable; ?></textarea>
<input type="button" name="convert" id="submitBtn" />
</form>

Link to comment
Share on other sites

Okay, try something like this:

<script type="text/javascript">
   window.onload = function()
   {
      var submitBtn = document.getElementById("submitBtn");
      var elm1 = document.getElementById("elm1");

      submitBtn.onclick = function()
      {
         elm1.setAttribute("id", "idRemoved");
      }
   }
</script>

.
.
.

<form name="Name" method="post" action="#">
<textarea name="elm1" wrap="virtual" class="inputTextStyle" id="elm1"><?php echo $variable; ?></textarea>
<input type="button" name="convert" id="submitBtn" />
</form>

 

Doesn't seem to work matey, I checked my code against yours , seems fine, Error Msg: expected object

 

 

 

Link to comment
Share on other sites

Yeah, it works in Firefox, but not IE (what else is knew?  :-\ ).

 

Unfortunately, trying the direct approach (i.e., elm1.id = "idRemoved") isn't showing any changes to the source when I try it in IE, either.  Of course, given how IE works, it may actually be working with that behind the scenes, so try the direct version.

Link to comment
Share on other sites

Yeah, it works in Firefox, but not IE (what else is knew?  :-\ ).

 

Unfortunately, trying the direct approach (i.e., elm1.id = "idRemoved") isn't showing any changes to the source when I try it in IE, either.  Of course, given how IE works, it may actually be working with that behind the scenes, so try the direct version.

 

Of cors, IE doesn't does IT , GRRRR , why be so awkward Microsoft

Link to comment
Share on other sites

Hey, I just did a check: both versions work in IE7.  The id change doesn't show up in the source code, but it works.  You can see it in action here: http://www.nightslyr.com/elm1.html

 

You'll notice that the textarea border changes from red to green when the button is clicked.

 

How strange...??

 

So why is it, when i am Copying the exact code you have i am Get EXPECTED OBJECT..?

 

I will have another look

 

Cheers Mate

Link to comment
Share on other sites

I got it to work now matey, Nice one...

 

I have another question now,

 

No I have that workin i have now i have now been able to use node.replaceChild,

 

And evething is working Great until i want to add the CONTENT to the new textarea,

 

The new content is a PHP Variable recovered from my database, When i do this:

 

	newElm.appendChild(document.createTextNode('<? echo $featureContent; ?>')); 

 

Its like the all the HTML stops executing..

 

I have also tried this

 

	newElm.appendChild(document.createTextNode('\<? echo $featureContent; ?>\')); 

 

Doesn't work..

 

I will drop all my code in, but that part is the pecific part i am after, as the rest works TIP TOP.

 

If n e one could help me with how to extract php in a JS would be grateful

 

   window.onload = function()
   {
		var textTag = document.getElementsByTagName('textarea');
      var submitBtn = document.getElementById("convertHtml");


      submitBtn.onclick = function()
      {
			var newTd = document.createElement('td')
			var newElm = document.createElement('textarea');
			newElm.setAttribute('name','htmlV');
			newElm.setAttribute('wrap','virtual');
			newElm.setAttribute('id','removed');
			newElm.className='inputTextStyle';
			newElm.appendChild(document.createTextNode(''));

			newTd.appendChild(newElm);

			for(i=0; i<textTag.length; i++)
			{
				if(textTag[i].getAttribute('name').toLowerCase() == 'elm1')
				{
					moveUp = textTag[i].parentNode;
				}
			}

			moveUp.parentNode.replaceChild(newTd, moveUp);
      }
   }

Link to comment
Share on other sites

Hmm...have you tried using innerHTML instead of creating a text node?  In other words:

newElm.innerHTML = "<? echo $featureContent; ?>";

 

Just tried that now Nightslyr, to no success i am afraid...

 

If i look at the source of the HTML, it echo's the PHP, and displays it in the source, but doesnt change wen clicked..??

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.