Jump to content

[SOLVED] Change txt from users input


pleek

Recommended Posts

ok i found this code

 

<script type="text/javascript">
function changeText(){
document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';
}
</script>
<p>Welcome to the site <b id='boldStuff'>dude</b> </p> 
<input type='button' onclick='changeText()' value='Change Text'/>

 

Now my question is how can i change that so i can input what i want the id "boldStuff" to say? I want to be able to enter in say my name, click "Change Text" and it change dude to my name.

 

Thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/146445-solved-change-txt-from-users-input/
Share on other sites

<script type="text/javascript">
function changeText(myname){
   document.getElementById('boldStuff').innerHTML = myname;
}
</script>
<p>Welcome to the site <b id='boldStuff'>dude</b> </p>
<input type='button' onclick='changeText("John Doe")' value='Change Text'/>

um that pretty much does the same thing. What im talking about is like a input form. you type in your name and then click "change text" and the text changes to what you typed in.

 

well you didn't original say that; but i assume this is what you are talking about:

 

<script type="text/javascript">
function changeText(){
var myname = document.getElementById('name').value;
   document.getElementById('boldStuff').innerHTML = myname;
}
</script>
<p>Welcome to the site <b id='boldStuff'>dude</b> </p>
<input type="text" id="name">
<input type='button' onclick='changeText()' value='Change Text'/>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.