PDA

View Full Version : stupid.. stupid.. stupid mistake


gildash2
02-25-2004, 12:00 AM
<SCRIPT language="JavaScript">
function dic()
{
var bobj = document.bob.bob1.value;
var bobx = document.bob.bob2.value;

if(bobj == "J")

{
bobx="bkfdhkhjlgfhksglfkhjsdfkhjsdfkjslkhjslj";
}
else
{
alert('word doesnot compute');
}
}
</script>


<form name="bob">
<input type="button" value="click" onClick="dic()">
<input type="text" name="bob1" height="5" size="15"><br><input name="bob2" type="textarea" height="50" widht="6"></form>
could some1 please tell me whats wrong with this script?
what im trying to do is if the text box value is equal to a certain thing, then i want the text area to equal another, if it doesnt equal that certain thing, then i want an alert box to appear, its not working, please experts, edit my code, all help and any will be appreciated

ucm
02-25-2004, 03:45 AM
got it...

what's going on is that you tried to create an object reference ( bobj )... but when you set an object reference to an object's property, then an object reference isn't created and instead, the variable becomes the value of that object's property...

so in effect, you're bobj becomes a string which is filled with the text typed in bob1...

to overcome this, you just remove the .value from bobx and bobj then they will become object reference variables... now you add .value to if(bobj == "J") line after bobj and it'll reference things correctly...


to sum it up, the .value's are strings and the bob1 and bob2 are objects so the browser's javascript compiler thought you were making bobj and bobx string values instead of your intended object reference vaiables ;)


also widht="6" is a typo ;)