Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: VBscript vs JavaScript


Message #1 by "Michael Goldman" <mg188@h...> on Tue, 28 Nov 2000 14:26:54 -0800
Thanks Imar,

I fixed the code with the "&&" and "==".  Works great. I need the "newitem"
for a textarea because the user must either pick an existing item or create
a new one (wierd, huh).
----- Original Message -----
From: "Imar Spaanjaars" <Imar@S...>
To: "javascript" <javascript@p...>
Sent: Wednesday, November 29, 2000 12:50 AM
Subject: [javascript] Re: VBscript vs JavaScript


> Hi there,
>
> I have changed your code a little to show you some basic principles.
> Note that I left out the check for newitem.value, since I didn't know what
> it was. (Another listbox maybe??)
>
> <CODE HERE>
> <script Language="JavaScript">
> <!--
> function chkfrm()
> {
>          if (document.frmadd.lstTest.selectedIndex == 0)
>          {
>                  alert("Please select or add at least one activity");
>                  return false;
>          }
>          return true;
> }
> -->
> </script>
>
> <form name="frmadd">
>          <select name="lstTest">
>                  <option value=""></option>
>                  <option value="1">1</option>
>          </select>
>          <input type="button" onClick="chkfrm();" name="btnClick"
> value="click">
> </form>
> </code here>
>
>
> First I have created a form named frmadd with one select box with two
> values (empty and 1). When I click the button chkfrm is run.
> I don't pass the form since this form is the only one on the page. You
> could however pass it and then use that in your function if you wish.
> Now all the names are hardcoded in the function (like
> document.frmadd.lstTest), but you can of course change that too.
>
> Then the chkfrm function.  It's mainly your own code, except that in
> JavaScript AND does not exist. You have to use && instead of AND.
> Also, if you ever need OR, use ||
>
> Also, comparing values can't be done with an equal sign. That will assign
a
> value instead of comparing it.
> Use == to compare 2 values (as in: document.frmadd.lstTest.selectedIndex
== 0 )
>
> HtH
>
> Imar
>
>
>
> At 08:47 AM 11/29/2000 -0800, you wrote:
> >Hi,
> >My form has a select box filled with items from the database; and a text
> >area where the user can add new items.
> >I want a client-side script to check that at least one item is selected,
OR
> >that at least one item is entered in the textarea.  The following
vbscript
> >works in Internet Explorer, but, being VBscript, it doesn't work in
> >Netscape.
> >
> ><script language=vbscript>
> >sub btnsubmit_onclick()
> >if (len(frmadd.item.value)=0 and len(frmadd.newitem.value)=0) then
> >  alert "please select or add an item"
> >exit sub
> >end if
> >call frmadd.submit()
> >end sub
> ></script>
> >
> >The following Javascript doesn't work.  In IE I get a missing ) error.
In
> >Netscape, the alert box doesn't come up when it should (no item selected
and
> >no newitem put in textarea).
> >I'm new to Javascript and not sure if my syntax is wrong or what.
> >
> >Any advice?
> >
> ><script Language="JavaScript">
> ><!--
> >function chkfrm(frmadd) {
> >
> >if ((frmadd item.selectedIndex = 0) and (frmadd.newitem.value.length 
0))
> >{
> >alert("Please select or add at least one activity");
> >frmadd.actnam.focus();
> >return (false); }
> >
> >return (true); }
> >--></script>
> >
> >
>

  Return to Index