From: jr on
I fixed what you suggested on Sunday, valid html and added the field
id's.. Below is the view source.
I cannot list the web page because it is an internal server.
You suggested to use a SelectedIndex instead of the option select and
testing for whether the selectedIndex value matches the index of that
option.
I will try it, I do want to vaidate for user errors. In order to do it
I have to change the way mysql pulls the data from the database.
First, I would like to get one of the validations to work. Right now
this
line doesn't work at all. I'm not getting any messages so something
is wrong with the javascript or the onsubmit .

method='post' onsubmit='return validate_form(this);

Should it be (thisform) instead of (this)??
thanks,
---------------view source--------

<html>
<head>
<title>Print Barcode Labels</title>

<script language='javascript'>
function validate_form(thisform) {
var sMsg='';
var sSel='N';
with (thisform) {
if ( document.getElementByID('bu').value=='' ) { sMsg
+="No bu\r\n"; }
for (i = 1; i < bu.length; i++) {
if ( bu[i].selected) { sSel='Y'; }
}
if ( sSel=='N' ) { sMsg+="No BU selected\r\n"; }


if (document.getElementByID('zoneid').value !=''&&
document.getElementById('zonenm').value==''){
alert('Missing zone number.');
return false;}
}


if ( sMsg.length > 0 ) {
alert(sMsg);
return false;
}else{
return true;
}
}
</script>

</head>

<body>


<h2 align='center'>Print Barcode Lables</h2>
<form enctype='multipart/form-data' action='' method='post'
onsubmit='return validate_form(this);'><table cellpadding='3'
cellspacing='0' border='0' style='border:1px solid #CCCCCC'
align='center'>
<th colspan='2'><span class='ast'>*</span>Search for Labels to Print
<tr>
<th align='right'><span class='ast'>*</span>BU
<td><select name='bu' >
<option value=''>Select BU</option>
<option value='08005'>08005</option>
<option value='08010'>08010</option>
<option value='08020'>08020</option>
<tr>
<th align='right'>Zone ID
<td><input type='text' name='search_zoneid' size='20' id='zoneid'>
<tr>
<th align='right'>Zone Number
<td><input type='text' name='search_zonenm' size='20' id='zonenm'>
<tr>
<th align='right'>NDC
<td><input type='text' name='search_nationalDrugCode' size='20' >
<tr>
<td align='center' colspan='2'><input type='submit' value='Search'>
</table>
<tr>
<td><span class='ast'>*</span> - <font size='-1'><i>Required</i>
</table>
</form></body>
</html>
thanks very much
From: Jukka K. Korpela on
jr wrote:

> I fixed what you suggested on Sunday, valid html and added the field
> id's.. Below is the view source.

Are you commenting on something? Then please post a followup article, with
adequate quotation or paraphrase of previous discussion, instead of starting
a new thread.

> I cannot list the web page because it is an internal server.

Then it's not a web page, by definition. That doesn't matter, as such, but
if you expect others to help you, you should construct a publishable example
of the issue and post its URL.

> You suggested to use a SelectedIndex instead of the option select and
> testing for whether the selectedIndex value matches the index of that
> option.
> I will try it, I do want to vaidate for user errors. In order to do it
> I have to change the way mysql pulls the data from the database.

That sounds weird (constructing HTML markup is something quite different
from extracting data from a database, and although one might affect the
other, this does not seem to be such a situation), but that's really
off-topic.

> First, I would like to get one of the validations to work. Right now
> this
> line doesn't work at all. I'm not getting any messages so something
> is wrong with the javascript or the onsubmit .
>
> method='post' onsubmit='return validate_form(this);

You're missing a closing apostrophe. Maybe your real code has that flaw,
maybe not. Do you see the point in posting a URL?

> Should it be (thisform) instead of (this)??

If you refer to form fields by their id attributes, you won't need any
parameter for the function.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

From: Richard Cornford on
On Jun 28, 4:51 pm, jr wrote:
> I fixed what you

Who?

> suggested on Sunday, valid html and added the field id's..

Valid HTML is a good idea, but why add ID attributes to form controls
that already need to have NAME attributes in order to be
'successful' (submitted to the server)? There is a fully standardised,
back-compatible and reliable mechanism for accessing form controls
using their NAME attribute's values so adding IDs is just adding
complexity for no benefit.

> Below is the view source. I cannot list the web page because
> it is an internal server. You suggested to use a SelectedIndex

That would be - selectedIndex - in case-sensitive javascript.

> instead of the option select

Hu?

> and testing for whether the selectedIndex value matches the
> index of that option.
> I will try it, I do want to vaidate for user errors. In order
> to do it I have to change the way mysql pulls the data from
> the database. First, I would like to get one of the validations
> to work. Right now this line doesn't work at all.

In the sense that it will be doing precisely what you programmed it to
do, it does 'work'. A failure to do what you expect/want something to
do is a condition that has symptoms; a specific difference (or
specific differences) between what you want/expect and what actually
happens. The diagnosis of the cause and effect relationships behind
faults of various sorts is often based on symptoms, so keeping them to
yourself is not going to help.

> I'm not getting any messages so something
> is wrong with the javascript or the onsubmit .

The odds are very good that the browser(s) that you are using have a
faculty for reporting javascript errors, which take the form of error
messages. There are messages, they are javascript error messages, but
you are not looking at/for them and so not seeing them.

> method='post' onsubmit='return validate_form(this);
>
> Should it be (thisform) instead of (this)??

If you mean in the value of the onsubmit attribute in the mark-up,
then if you want to pass a reference to the FORM element as an
argument to the - validate_form - function then it should be - this -.

> thanks,
> ---------------view source--------
>
> <html>
> <head>
> <title>Print Barcode Labels</title>
>
> <script language='javascript'>
> function validate_form(thisform) {
> var sMsg='';
> var sSel='N';
> with (thisform) {
^^^^
Javascript's - with - statements are generally introducers of code
obscurity, the concealers of errors, and inefficient in execution.

> if ( document.getElementByID('bu').value=='' ) { sMsg

Case-sensitive javascript will probably not be happy to see the
capital D in your - getElementByID - . However, the mark-up at the end
of your post does not contain any elements with the ID 'bu'. There is
an element with the NAME 'bu', but obviously a method named
getElementById is not an appropriate means of accessing it. See:-

<URL: http://jibbering.com/faq/faq_notes/form_access.html >

> +="No bu\r\n"; }
> for (i = 1; i < bu.length; i++) {
^^

This unqualified use of the Identifier 'bu' is either relying on a
global reference to the form control under that name (which will exist
in some environments, but not most, and certainly only in a
proprietary way) or on the FORM element added to the scope chain with
the - with - statement having a property named 'bu' that refers to the
control. In practice forms are likely to have properties named for
each form control with a NAME attribute, but that approach is also non-
standard (for the time being).


> if ( bu[i].selected) { sSel='Y'; }

This is a bit of a mess. Why mess around with - sSel - at all (and if
you are going to do that why a string when the concept is clearly
boolean)? If any single instance of bu[i].selected having trueness is
sufficient to mean no messages then there should be a - break;' -
statement at the end of the - if - body (so the - for - loop is
terminated), and since that would mean the - if - body could then only
be entered once the - sMsg - could be set at that point.

However, presuming that the 'bu' element is a SELECT element then
iterating over its integer indexed properties to access the OPTION
elements is yet another proprietary feature, and the W3C DOM standard
- options - collection should be used instead. (and the SELECT
element's - selectedIndex - property is the index into this collection
of the selected OPTION element (assuming that this is not a 'multiple'
SELECT element), so looping should not be necessary at all.


> }
> if ( sSel=='N' ) { sMsg+="No BU selected\r\n"; }
>
> if (document.getElementByID('zoneid').value !=''&&
> document.getElementById('zonenm').value==''){
<snip> ^^

Bad as it is, with the correct use of case in the Identifiers your
code would 'work'.

Richard.
From: Thomas 'PointedEars' Lahn on
Jukka K. Korpela wrote:

> jr wrote:
>> First, I would like to get one of the validations to work. Right now
>> this line doesn't work at all. I'm not getting any messages so something
>> is wrong with the javascript or the onsubmit .
>>
>> method='post' onsubmit='return validate_form(this);
>
> You're missing a closing apostrophe. Maybe your real code has that flaw,
> maybe not. Do you see the point in posting a URL?

There is no point in posting the URL if the real code is posted. But this
code is FUBAR since the OP did not do their homework. Again (previously it
was "JRough").

>> Should it be (thisform) instead of (this)??

Not with the call.

> If you refer to form fields by their id attributes, you won't need any
> parameter for the function.

It is still bad advice.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: jr on
On Jun 28, 10:29 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> Jukka K. Korpela wrote:
> > jr wrote:
> >> First, I would like to get one of the validations to work.  Right now
> >> this line doesn't work at all.  I'm not getting any messages so something
> >> is wrong with the javascript or the onsubmit .
>
> >> method='post' onsubmit='return validate_form(this);
>
> > You're missing a closing apostrophe. Maybe your real code has that flaw,
> > maybe not. Do you see the point in posting a URL?
>
> There is no point in posting the URL if the real code is posted.  But this
> code is FUBAR since the OP did not do their homework.  Again (previously it
> was "JRough").
>
> >> Should it be (thisform) instead of (this)??
>
> Not with the call.
>
> > If you refer to form fields by their id attributes, you won't need any
> > parameter for the function.
>
> It is still bad advice.
>
> PointedEars
> --
> Prototype.js was written by people who don't know javascript for people
> who don't know javascript. People who don't know javascript are not
> the best source of advice on designing systems that use javascript.
>   -- Richard Cornford, cljs, <f806at$ail$1$8300d...(a)news.demon.co.uk>
I checked and the the onsubmit line is correct.
I just added the thisform in the javascript and the this in the form
and now it works in I.E. I don't know if it worked before that or not
because I didn't try it in I.E.
It works in I.E. but not Chrome? I was testing in Chrome.

Thanks to both of you.
----source-----
<html>
<head>

<title>Print Barcode Labels</title>

<script language='javascript'>
function validate_form(thisform) {

var sMsg='';
var sSel='N';
with (thisform) {


if ( document.getElementById('bu').value=='' ) { sMsg
+="No bu\r\n"; }
for (i = 1; i < bu.length; i++) {
if ( bu[i].selected) { sSel='Y'; }
}
if ( sSel=='N' ) { sMsg+="No BU selected\r\n"; }


if (document.getElementById('zoneid').value !=''&&
document.getElementById('zonenm').value==''){
alert('Missing zone number.');
return false;}
}


if ( sMsg.length > 0 ) {
alert(sMsg);
return false;
}else{
return true;
}
}
</script>
<style>
.ast { color:red; }
td {font-family:verdana; font-size:12px; line-height:12pt;}
th {font-family:verdana; font-size:12px; line-height:12pt;}
.txt1 {font-family:verdana; font-size:20px;}
a:link {color: blue; text-decoration: none;} /* unvisited link */
a:visited {color: blue; text-decoration: none; } /* visited link */
a:hover {color: #FF00FF} /* mouse over link */
</style>
</head>

<body>





<a href='admin.php'>Admin Menu<a/><br>
<h2 align='center'>Print Barcode Lables</h2>
<form enctype=;multipart/form-data' action='' method='post'
onsubmit='return validate_form(this);'>
<table cellpadding='3' cellspacing='0' border='0' style='border:1px
solid #CCCCCC' align='center'>
<th colspan='2'><span class='ast'>*</span>Search for Labels to Print
<tr>
<th align='right'><span class='ast'>*</span>BU
<td><select name='bu' >
<option value=''>Select BU</option>
<option value='08005'>08005</option>
<option value='08010'>08010</option>
<option value='08020'>08020</option>
<tr>
<th align='right'>Zone ID
<td><input type='text' name='search_zoneid' size='20' id='zoneid'>
<tr>
<th align='right'>Zone Number
<td><input type='text' name='search_zonenm' size='20' id='zonenm'>
<tr>
<th align='right'>NDC
<td><input type='text' name='search_nationalDrugCode' size='20' >
<tr>
<td align='center' colspan='2'><input type='submit' value='Search'>
</table>
<tr>
<td><span class='ast'>*</span> - <font size='-1'><i>Required</i>
</table>
</form></body>
</html>


When I have another question I will create the form on my home
server.