PDA

View Full Version : Looking for a script...


JamesBond
03-15-2003, 10:20 AM
I've seen this done before, and if I am not mistaken, it was Javascript that made it happen. If someone could help me find this script, that would be AWESOME!

Basically I am looking for something that changes text on a web page depending on what the viewer selects from a drop down menu toolbar.

Anyone know what I am talking about, and shed some scripting on the subject?

Thank you!
JamesBond

kwhubby
03-15-2003, 10:33 AM
are you talking about something that changes the innerHTML of a page, yes its quite easy. a quick little example of maby what your talking about
<html>
<body>
<select OnChange="document.all.abc.innerHTML= this.value">
<option value="" selected>select 1 or 2
<option value="this is text<font color='red'><big> this is bigger text">1
<option value="this is other text<font color='green'><big> this is bigger green text">2
</select>
<p id="abc">
</p>
</body>
</html>

JamesBond
03-15-2003, 08:54 PM
There's got to be more to it than that, because nothing is happening, i even tried copying and pasting exactly what you posted, and still nothing.

Is there supposed to be a javascript within the header or something too?

JamesBond

cheesebagpipe
03-15-2003, 10:51 PM
hey 007...

Pretty basic but should give you a starting point:

<html>
<head>
<script type="text/javascript">

function insert(el_id, text) {
var el = document.getElementById(el_id);
if (el && typeof el.innerHTML != 'undefined') el.innerHTML = text;
}

</script>
</head>
<body>
<form>
<select onchange="if(selectedIndex)insert('placeholder',options[selectedIndex].value)">
<option>Choose Text</option>
<option value="superb!">superb</option>
<option value="not bad...">OK</option>
<option value="average, Jack.">average</option>
<option value="sucky.">sucky.</option>
<option value="...script? What script?">...d'oh..</option>
</select>
</form>
<br /><br /><br /><br />
<h3>This script is <span id="placeholder"></span></h3>
</body>
</html>

JamesBond
03-16-2003, 12:37 AM
Perfect cheesebagpipe!

One more thing, I want to use the option that they select in more than one spot on the page. If this is possible how do I do that? I tried giving it a <select name="name_i_gave_it"> and then did a <span id="name_i_gave_it"></span> but that didnt work.

Any suggestions?
007

cheesebagpipe
03-16-2003, 12:55 AM
OK, modified it a bit...

<html>
<head>
<style type="text/css">

#block {
font: 200 24px "comic sans ms";
color: darkred;
}

</style>
<script type="text/javascript">

function insert(HTML) {
for (var el,arg,i=1;arg=arguments[i];++i) {
el = document.getElementById(arg);
if (el && typeof el.innerHTML != 'undefined') el.innerHTML = HTML;
}
}

</script>
</head>
<body>
<form>
<select onchange="if(selectedIndex)insert(options[selectedIndex].value,'placeholder1','placeholder2','placeholder3','placeholder4')">
<option>Choose Text</option>
<option value="Cleveland">Cleveland</option>
<option value="Baghdad">Baghdad</option>
<option value="Cabo San Lucas">Cabo San Lucas</option>
<option value="Hell">Hell</option>
<option value="Antarctica">Antarctica</option>
</select>
</form>
<br /><br /><br /><br />
<div id="block">
I spent my last vacation in <span id="placeholder1">*****</span>&amp;nbsp;. Although I'd never been to <span id="placeholder2">*****</span>&amp;nbsp;before, people who live in <span id="placeholder3">*****</span>&amp;nbsp;insist that it's the greatest place on earth...ahh, what do people from&amp;nbsp;<span id="placeholder4">*****</span>&amp;nbsp;know anyway?
</div>
</body>
</html>

kwhubby
03-16-2003, 02:41 AM
well mine does not work if your NOT using something other than IE, because document.all is ie only mine would work if you replaced document.all.abc with document.GetElementById("abc")


ps for simple stuff like puting some text into the document like cheesebridge did, I recomend using innerText, instead of innerHTML.