Click to See Complete Forum and Search --> : how to use if/or?


Tereno
10-25-2003, 08:41 PM
how do i use if or inside this script?

<form name="myform">
<input type="text" name="answer"/>
<button onclick="javascript:if (myform.answer.value=='theanswer') {alert('Right!');} else

{alert('Wrong!');}">Check my answer!</button>
</form>

Shampie
10-25-2003, 08:56 PM
do you mean:

var a = 10;
var b = 11;
var c = 9;

if(a > c || c < a){
alert("so be it");
}

the || is OR
use && if it should include ->

if( a > c && a < b){
alert("a ="+a+"");
}

&& : and
|| : or
<= : less than or equal to.
>= : more then or equal to.
!= : is not
++ :add 1 to
-- :subtract 1 from
== :equal to
= : asign to
! : not

Jona
10-25-2003, 09:50 PM
Because the form's purpose is exclusively for JavaScript, you should generate it with JavaScript so that those without JavaScript enabeld will not see a form and not be able to make use of it. I have also corrected your XHTML, as far as a few of the errors I saw.


<script type="text/javascript"><!--
document.write('<form action="" id="myform"><div>\n');
document.write('<input type="text" name="answer" /><br>\n');
document.write('<button onclick="if(this.form.answer.value==\"theanswer\"){alert(\"Right!\");}else {alert(\"Wrong!\");}">Check my answer!</button>\n');
document.write('</div></form>');
//--></script>

[J]ona