Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I change HTML element: show "input" instead of "a"?

Newbie
 
Join Date: Jul 2007
Posts: 2
#1: Jul 23 '07
Hello!

I would like to switch elements on the fly.
Dynamicly turn "A" elenent an "input" tag.

This is what I tried:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script>
  4. function insertTableRow(ref, arg)
  5.     var whichID = ref.parentNode.id;
  6.  
  7.     if (arg=='header'){
  8.         document.getElementById(whichID).Element='input';
  9. //        document.getElementById(whichID).class='prodDesc';
  10.         document.getElementById(whichID).style.display='';
  11.         document.getElementById(whichID).TYPE='text';
  12.         document.getElementById(whichID).NAME='descriptionHeader';
  13.         document.getElementById(whichID).VALUE='new Header Content';
  14.     }
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <span id="menuoutline">incert in table: 
  20.             <a id="menuoutlineAHeader" href="#" onclick="insertTableRow(this, 'header')">header</a>
  21.             </span><BR>
  22. </body>
Could you please help make it work?

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Jul 24 '07

re: How do I change HTML element: show "input" instead of "a"?


Heya, Apple1. Welcome to TSDN!

Instead of giving yourself massive headaches, simply add an INPUT with style="display:none;" to your HTML manually, then make insertTableRow() make the A invisible and the INPUT visible.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,134
#3: Jul 24 '07

re: How do I change HTML element: show "input" instead of "a"?


Yes ... that would be my recommendation too ;) ... however: in case you want the replacement ... you may play with the replaceChild()-method to achieve your goal ...

kind regards
Newbie
 
Join Date: Jul 2007
Posts: 2
#4: Aug 1 '07

re: How do I change HTML element: show "input" instead of "a"?


Thanks guys!

I had to leave my city for a couple of days. Your first advice was really helpful. Actually, I tried the second too, but it seemed to be way too complex for me (you were right).

Thanks again!
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Aug 1 '07

re: How do I change HTML element: show "input" instead of "a"?


Heya, Apple.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Reply