•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,030 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,848 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1173 | Replies: 3
![]() |
> Is this possible?
Yes, very much possible. Use the DOM API. Below I present a minimalistic code snippet which replaces a button element with a text element.
Yes, very much possible. Use the DOM API. Below I present a minimalistic code snippet which replaces a button element with a text element.
<html>
<head>
<script type="text/javascript">
function change(elem)
{
var newElement = document.createElement("input");
newElement.type = "text";
newElement.id = "txtName";
newElement.name = "txtName";
elem.parentNode.replaceChild(newElement, elem);
}
</script>
</head>
<body>
<form action="#">
<input type="button" name="btn" id="btn" value="Change on click" onclick="change(this);" />
</form>
</body>
</html> "I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
•
•
Join Date: Oct 2007
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
Thanks! That's great! It works perfectly!
•
•
•
•
> Is this possible?
Yes, very much possible. Use the DOM API. Below I present a minimalistic code snippet which replaces a button element with a text element.
<html> <head> <script type="text/javascript"> function change(elem) { var newElement = document.createElement("input"); newElement.type = "text"; newElement.id = "txtName"; newElement.name = "txtName"; elem.parentNode.replaceChild(newElement, elem); } </script> </head> <body> <form action="#"> <input type="button" name="btn" id="btn" value="Change on click" onclick="change(this);" /> </form> </body> </html>
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
This code is almost PERFECT for what I need. I want to display text, and replace it with another piece of text when the user clicks on the first text. So instead of using a button , I simply used a link:
But I want to now replace that $100, with say $80. Both these values are pulled from my database, they are product prices (original is the MAP price, while the second is the actual customer price).
<A onclick="change(this)">$100</A>
But I want to now replace that $100, with say $80. Both these values are pulled from my database, they are product prices (original is the MAP price, while the second is the actual customer price).
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Sharing object instances between applications (VB.NET)
- Object-Oriented Programming (C++)
- Help w/ constructors (Java)
- How to maintain session for Web Services Object? (VB.NET)
- infected, embedded object. (Viruses, Spyware and other Nasties)
- Print Object hierarchy (C)
- Finding and Replacing Strings (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Ie Display (mozilla Is Ok)
- Next Thread: document.getElementById problem



Linear Mode