mikePhp Posted July 29, 2008 Share Posted July 29, 2008 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??? Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/ Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602705 Share on other sites More sharing options...
mikePhp Posted July 29, 2008 Author Share Posted July 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602721 Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602729 Share on other sites More sharing options...
mikePhp Posted July 29, 2008 Author Share Posted July 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602770 Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602796 Share on other sites More sharing options...
mikePhp Posted July 29, 2008 Author Share Posted July 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602850 Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-602982 Share on other sites More sharing options...
mikePhp Posted July 30, 2008 Author Share Posted July 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-603404 Share on other sites More sharing options...
mikePhp Posted July 30, 2008 Author Share Posted July 30, 2008 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-603431 Share on other sites More sharing options...
KevinM1 Posted July 30, 2008 Share Posted July 30, 2008 Hmm...have you tried using innerHTML instead of creating a text node? In other words: newElm.innerHTML = "<? echo $featureContent; ?>"; Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-603479 Share on other sites More sharing options...
mikePhp Posted July 30, 2008 Author Share Posted July 30, 2008 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..?? Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-603484 Share on other sites More sharing options...
KevinM1 Posted July 30, 2008 Share Posted July 30, 2008 Mind sending me the web address of your site in a PM so I can look at it? Quote Link to comment https://forums.phpfreaks.com/topic/117122-solved-removing-an-id/#findComment-603491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.