Click to See Complete Forum and Search --> : Semi-Dynamic information from Select?


WinterGhost
04-15-2003, 07:11 PM
Er, I know the subject might not make any sense... but here is a better explanation. Now I program in PHP/Perl/MySql, but almost never use JS... I tried for a couple of hours to do this, to no avail.. so here is the problem.

What I would like, is a select box, for instance lets say there are a few states in there... So, You have Texas, Alabama, Oklahoma, Iowa, So these are the options in the select menu, now lets say someone selects Texas, What I would like it to do... is Put information about texas in a Textarea and then if they selected alabama afterwards, the texas information would be gone, and the alabama information would be there.

Now I've tried a few things, like onFocus="document.myform.display.value='This is stuff about texas...';"

And I've also tried onSelect, and also tried putting the onFocus into a function then calling the function from within the form... but still nothing... Will someone actually shine some light on this utter darkness I am experiencing? (please show some code) thank you for your help.

DrDaMour
04-15-2003, 07:37 PM
this code should get you started, it shows you how to hook the onChange event (not on select), i think you will know how to chang ethe values of a textarea. But i would suggest using
<div id=text> </div> text.innerHTML="YOUR HTML HERE" instead of a textarea. Would give you more options, hyperlinks and such...

<html>
<head>

</head>


<body>

<form id="test">
<select name="worldwide" size="1" onChange="alert(this.form.worldwide.options[this.form.worldwide.selectedIndex].value)">
<option value="47">47
<option value="46">46
<option value="45">45
<option value="44">44
<option value="43">43

</select>


</form>


</body>


</html>

WinterGhost
04-15-2003, 07:46 PM
Ok i tried this...

<html>
<head>

</head>


<body>

<form id="test">
<select name="worldwide" size="1" onChange="document.text.innerHTML='YOUR HTML HERE';">
<option value="47">47
<option value="46">46
<option value="45">45
<option value="44">44
<option value="43">43

</select>
<div id=text> </div>

</form>


</body>

Now, up there where you said about text.innerHTML, whats up with that, I am not a bit familiar, sorry. hrmph *kicks himself*

DrDaMour
04-15-2003, 07:57 PM
it's like dynamic html, you can set the html of that div however you want. But the div object is document.all.text not document.text as you have. and whatever replace the your html here, will be sent to the div named text. so if you put <a href=''>h</a> it'll send it, anyways i think that may be out of your league, i think you should ignore that, and instead pass the parameters in alert to some function where you check the passed value agaisnt whatever it is yoru options are, and do something according to that, like in an if-then tree.

WinterGhost
04-15-2003, 08:21 PM
Ok, I can get that to work, prints out whatever I have in the innerHTML=' ', ok, now how do I make it to where it actually returns different results DEPENDING on what is selected? I am sorry for being a pain, :'(

DrDaMour
04-15-2003, 08:31 PM
like i said you have to create a function and use an if then tree.

if you actually know php, this shouldn't be a problem. syntax for a js function is:

function name(params){




}

so just pass it that .value thing from my first reply, and that will be whatever the value of the option selected is. Then just do if (param == "some value") { blah.innerHTML = 'html according to value'}
else if....


and so on
then on the onchanged just change alert to name.

oh the params don't have types, so name would look like
name(theSelectedValue){
if (theSelectedValue == "texas") {....

WinterGhost
04-15-2003, 08:40 PM
<html>
<head>

</head>
<script language="javascript">
function checkStuff(statValue) {
if(statValue == "45") {
text.innerHTML='BLAH BLAH BLAH'
}
}
</script>
<body>

<form id="test">
<select name="worldwide" onChange="document.all.text.innerHTML=checkStuff(this.form.worldwide.options[this.form.worldwide.selectedIndex].value)">
<option value="47">47
<option value="46">46
<option value="45">45
<option value="44">44
<option value="43">43

</select>
<div id=text> </div>

</form>


</body>

Now I actually got it to do something rofl, it keeps saying undefined, every time I select anything, which blows ass... whats up with that shizat? Now I am actually learning here. *sits down steaming* btw DrDaMour, thank you for all of your help... you've been great!!

DrDaMour
04-15-2003, 08:44 PM
onChange="function()" not onChange="innerHTML="""

first you are calling the functin onchange, and teh fucntion changes teh innerhtml, second, in javascript, like php you have ot be acareful with quotes, see you were getting undefined because you had quotes ending the onchange field, but qupte opening it up again. But since that was totally uneeded to begin with don't fret about it. In short just have onchange call your function

WinterGhost
04-15-2003, 08:52 PM
OMG OMG OMG! Thanks DrDaMour!!! You're a freaking genious, hrm, I think I have it all figured out now, And now I know more then what I did. hehe, still its alot different then PHP or Perl... I still don't like it all that much lol... Thanks for your time and patients DrDaMour... and if you need any help with PHP, just lemme know :)

DrDaMour
04-15-2003, 09:26 PM
ha i never even knew what that word was. It's actually a pretty good word to use in help forums, i'll have to use it more. Althought i'm thinking it was just a typo

WinterGhost
04-15-2003, 09:33 PM
um, I did spell that right didn't I? I HATE ENGLISH! damn myself in america! rofl

WinterGhost
04-15-2003, 09:35 PM
Ok hold on a second, Patient is the same thing as Patient! They are... homonyms? or whats the word... oh screw it, Patients is the same as Patients!! HRMPH!

WinterGhost
04-15-2003, 09:44 PM
oh here is the dictionary definition...

Patient: 1.) a person who is under medical care. 2.) tolerating delay, provocation, annoyance, etc., without complaint or anger. 3.) Preserving or diligent.


BOOOOYAAAAH! Yes now I see the other one above that... but look...

Patience: the quality or capacity of being patient..



WHOS YOUR DADDY!?!

WinterGhost
04-15-2003, 11:37 PM
SO :(