OT: Javascript help?

Gene Dascher gedascher at multiservice.com
Tue Sep 3 18:56:52 CDT 2002


How are you passing in the field info to the function?

You should be passing it in like

stripBadchs(document.MyForm.MyField, "letters");

without quotes around the form field object string.  If you have to use
quotes or have to build the form field name string to pass in to the
function, then add this to the beginning of the stripBadchs function:

var	idObj;
idObj = eval(id);

then use idObj throughout that function instead of id.  Otherwise, using the
following:

 	alert(id.value);

	should display what you want.

Gene

> -----Original Message-----
> From: owner-kclug at marauder.illiana.net
> [mailto:owner-kclug at marauder.illiana.net]On Behalf Of Bradley Miller
> Sent: Tuesday, September 03, 2002 1:45 PM
> To: Jason Clinton
> Cc: kclug at kclug.org
> Subject: Re: OT: Javascript help?
>
>
> At 01:28 PM 9/3/02 -0500, Jason Clinton wrote:
> >Have id and status been declared as global variable?
>
> Here's the entire enchilda -- like I said I can't think of how to get the
> "id" to refer to my "documents.MyForm.FieldName" properly.  The alert box
> just says (literally) "documents.MyForm.FieldName.value" and doesn't give
> the actual VALUE of that FieldName field.  (Price is what I'm trying to
> fix, so nobody bozos the $, stuff.)  If I change the script to say
> "documents.MyForm.FieldName" everywhere instead of the "id" it
> works great,
> but I can't guarantee that each instance will always be called
> "FieldName".
>  I might add 12 more Price fields (Price1,Price2,etc...) and I would want
> the script to work with each of those independently.  Does this
> make sense ?
>
>
> <script>
> <!--
> // Expects to receive the name or the identifier for a form object (id)
>
>
> 	// and a string (status) indicating what characters are permissible.
>
>
>
>
> 	function stripBadchs(id,status) {
>
>
> 	alert(id + ".value");
>
>
> 	  var bad = 0
>
>
> 	  for (i = 0; i < id.value.length; i++) {
>
>
> 	    ch = id.value.substring(i, i + 1);
>
>
> 	    if ( status == "letters or numbers" ) { if ( (ch < "a"
> || "z" < ch) &&
> (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) ) { bad = 1; } }
>
>
> 	    if ( status == "letters" ) { if ( (ch < "a" || "z" <
> ch) && (ch < "A"
> || "Z" < ch) ) { bad = 1; } }
>
>
> 	    if ( status == "dollar value" ) { if ((ch == "$") ||
> (ch == ",")) {
> bad = 1 } }
>
>
> 	    if ( status == "numbers" ) { if (ch < "0" || "9" < ch)
> { bad = 1 } }
>
>
> 		if ( bad == 1 )

>
>
> 	      id.value =
> id.value.substring(0,i)+id.value.substring(i+1,id.value.length)
>
>
> 	      i=i-1
>
>
> 	      bad = 0
>
>
> 	    }
>
>
> 	  }
>
>
> 	}
>
> // -->
>
> </script>
>
>




More information about the Kclug mailing list