Hi,
I want a js-function which changes the text of a html-textfield.
How can I do this?
Thanx...
p-flash
| SitePoint Sponsor |
Hi,
I want a js-function which changes the text of a html-textfield.
How can I do this?
Thanx...
p-flash





lots of ways to do this
a couple
PHP Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function CngName(m){
newname=window.prompt('Hi\nEnter your name below','');
newname='My Name is '+newname
if (m){
document.getElementById('Example').value=newname;
}
else {
document.Fred.Example.value=newname;
}
}
//-->
</script></head>
<body>
<form name="Fred" >
<input id="Example" name="Example" value="My Name is Fred">
</form>
<br>
<input type="button" name="" value="Method 1 using 'name'"
onclick="javascript:CngName(0);"
style="width:200px;font-size:12px;"
>
<br>
<input type="button" name="" value="Method 2 using 'getElementById'"
onclick="javascript:CngName(1);"
style="width:200px;font-size:12px;" >
<br>
<input type="button" name="" value="My Name is Tom with no prompt"
onclick="javascript:document.getElementById('Example').value='My Name is Tom';"
style="width:200px;font-size:12px;" >
<br>
</body>
</html>





You can set the value of a textbox by setting its .value property to some text:
document.getElementById("elmtID").value = "hello world";
Thank you, it works!
p-flash





another way is
<head>
<script language="Javascript">
function setText(){
var Text = prompt('Please insert your text','');
if (Text) {
test.innerHTML = Text;
}
else
{
test.innerHTML = "No text defined";
}
}
</script>
</head>
<body onLoad="setText();">
<span id="text"></span>
What this will do is ask for what text to use, then inserts it, if none is given then it will set another one. and there are no text boxes to be seen, this is directly inserted into the page.
Gav
Bookmarks