Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change text at runtime

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there anyone who can help me solve this problem?

I have a dropdown <select> say with the options of 1, 2, 3... Next to it, I would like to display the equivalent words of the selectedItem.. say I selected 2, next to it must have a text that has the words &quot;two&quot;, I selected 3, I change the &quot;two&quot; to &quot;tree&quot;...
is this even possible?

Thank you.

 
Mikey, try this one at home if you dare, simply cut it copy it and paste it into a new page and it will do what you want it to do

<html>
<head>
<title>Try This</title>
</head>

<script language=&quot;JavaScript&quot;>

function text()
{
if (document.f.s.value == 1)
{
document.f.t.value = 'One'
}
if (document.f.s.value == 2)
{
document.f.t.value = 'Two'
}
if (document.f.s.value == 3)
{
document.f.t.value = 'Three'
}
};
</script>
<body>

<table align=left>
<form method=post name=f>
<select name=s size=1 onchange=text()>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<input type=text name=t value=One>
</form>
</table>
</body>
</html>


If you get stumped, scream!!!!! DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Thanks DeltaFlyer, thanks for replying....but is there a way to have the value of a static text instead of an field (<input>)?

Miketb
 
I don't think that is possible, i may be mistaken but i have tried to do that before without success.

If you want to ensure that the field is not tampered with you could add a READONLY tag to the input box,
i.e. <input type=text name=t value=One readonly>

Jared, if you see this could you please let me know if this is possible?
DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
this will work in IE4+ and NS6+:

<script>

function changeText(obj)
{
if(document.getElementById)
{
var el = document.getElementById(&quot;textview&quot;)
}
else
{
var el = textview
}
el.innerHTML=(obj.value==1)?&quot;One&quot;:(obj.value==2)?&quot;Two&quot;:&quot;Three&quot;
}

</script>

</head>

<body>


<select onChange=&quot;changeText(this)&quot;>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
<option value=&quot;3&quot;>3
</select><span id=&quot;textview&quot;></span> jared@aauser.com -
 
Thanks jaredn and Deltaflyer, this is exactly what I need.

Thanks.

miketb
 
Thanks jaredn and Delta, this is exactly what I need.

Miketb
 
Glad to be of help Mike, but credit where credit's due Jared had the real answer.

Jared, thanks for that i have been trying for ages to figure that one out. P.S. congratulations on the new job.

DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top