Javascript въпрос ?

c1ko2

Registered
Тук имам един скрипт:
Код:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>Test</title>


<script type="text/javascript">
if(document.getElementById) {
var getRefById = function(id) {
return document.getElementById(id);
};
} else if(document.all) {
var getRefById = function(id) {
return document.all[id];
};
} else {
var getRefById = function() {
return null;
};
}

function insertText(str) {
var e = getRefById('test2'), s = null, r = null;

if(e) {
if((s = document.selection) && s.createRange) {
var repos = false;

/* Element must have focus otherwise text
* will be written into other elements. */
e.focus();
if((r = s.createRange())) {
if(r.text.length) {repos = true;}
r.text = str;
/* Clear the selection to stop continuous
* overwriting of inserted text. */
if(repos && s.empty) {s.empty();}
}
} else {
e.value += str;
}
}
}
</script>
</head>

<body>
<div>
<img src="http://www.mysmiley.net/imgs/smile/happy/happy0161.gif" alt="Happy" onclick="insertText(':)')">
<img src="http://www.mysmiley.net/imgs/smile/sad/sad0120.gif" alt="Sad" onclick="insertText(':(')">
</div>
<div>

<input type="text" size="35" id="test2" value="" />
</div>
</body>
</html>

искам вместо, като натиснеш друга картинка да се замества кода, а не да се добавя след първия.
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>Test</title>


<script type="text/javascript">
if(document.getElementById) {
var getRefById = function(id) {
return document.getElementById(id);
};
} else if(document.all) {
var getRefById = function(id) {
return document.all[id];
};
} else {
var getRefById = function() {
return null;
};
}

function insertText(str) {
var e = getRefById('test2'), s = null, r = null;

if(e) {
if((s = document.selection) && s.createRange) {
var repos = false;

/* Element must have focus otherwise text
* will be written into other elements. */
e.focus();
if((r = s.createRange())) {
if(r.text.length) {repos = true;}
r.text = str;
/* Clear the selection to stop continuous
* overwriting of inserted text. */
if(repos && s.empty) {s.empty();}
}
} else {
e.value = str;
}
}
}
</script>
</head>

<body>
<div>
<img src="http://www.mysmiley.net/imgs/smile/happy/happy0161.gif" alt="Happy" onclick="insertText(':)')">
<img src="http://www.mysmiley.net/imgs/smile/sad/sad0120.gif" alt="Sad" onclick="insertText(':(')">
</div>
<div>

<input type="text" size="35" id="test2" value="" />
</div>
</body>
</html>
пробвай така
 
Не знам за теб ама на мен сега изобщо не работи :idea:
:oops: Аз го оправих да работи, ама пак не се замества.
 

Горе