...

View Full Version : Validating Multiple Conditions



maryjane9110024
09-12-2011, 05:06 PM
Hi! I am trying to check and see if three fields are empty and if they are then to alert the user saying to fill in one of the three fields. I tried this:


if (StreetNumber.value.length == 0) {
if (StreetName.value.length == 0) {
if (City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}
}
}


and this:



if (StreetNumber.value.length == 0 && StreetName.value.length == 0 && City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}


Neither one works. Not sure what I am doing wrong.
Thanks in advance!:thumbsup:

Old Pedant
09-12-2011, 08:34 PM
Would help if you showed the HTML that this JS is referring to.

If I were *guessing*, I'd assume you have something like this:


<form id="myForm">
<input name="StreetNumber" />
...

In which case you should probably be referencing the form:


var form = document.getElementById("myForm");
if ( form.StreetNumber.value.length == 0
&& form.StreetName.value.length == 0
&& form.City.value.length == 0)
{
alert("Please enter a street number, street name, or city.");
form.StreetNumber.focus();
return false;
}


But do you really consider that adequate validation?? Means that a person could enter a SINGLE SPACE into each of those form fields and you would consider them valid.

On top of that, would it *REALLY* be okay with you if the user entered just "17" as his street number and no street name and no city??? That's what the logic of your code is saying.

niralsoni
09-12-2011, 08:52 PM
replace && with || (and with or) in the example you have provided...



if (StreetNumber.value.length == 0 || StreetName.value.length == 0 || City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}


Thanks & Regards,
Niral Soni

maryjane9110024
09-12-2011, 09:05 PM
@Old Pendent ... yes it *REALLY* is. they can enter just the street number or the street name or the city and do a search. I can't post all the code its too long. The form is 2 text boxes and a drop down list. I have the pieces in a function... Here's the complete function:


function validateOption1(PropertyAddressSearch) {

var StreetNumber = document.getElementById('StreetNumber');
var StreetName = document.getElementById('StreetName');
var City = document.getElementById('City');

if (StreetNumber.value.length == 0) {
if (StreetName.value.length == 0) {
if (City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}
}
}

// if (StreetNumber.value.length == 0 && StreetName.value.length == 0 && City.value.length == 0) {
// alert("Please enter a street number, street name, or city.");
// StreetNumber.focus();
// return false;
// }

if (StreetNumber.value.length != 0) {
if (StreetNumber.value.match(numExp)) {
}
else {
alert("Please enter a valid street number.");
StreetNumber.focus();
return false;
}
}


}

@niralsoni ... only one field is required not all so using the OR conditional is not correct. I need to check IF 3 fields are empty to send an alert as indicated in my original post.

Old Pedant
09-12-2011, 10:02 PM
Dunno.

At least show the <form>...</form>?

Or the three form fields?

maryjane9110024
09-12-2011, 10:29 PM
<form id="PropertyAddressSearch" action="">
<table>
<tr>
<td colspan="6"><b><span class="blue">Option One</span> Property Address Search:</b></td>
</tr>
<tr>
<td>Street Number</td>
<td>Street (Name Only)</td>
<td>City</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="StreetNumber" name="StreetNumber" type="text" /></td>
<td>
<input id="StreetName" name="StreetName" type="text" /></td>
<td>
<select id="City" name="City">
<option value="">- Please Select -</option>
<option value="I don't know">I don't know</option>
<option value="Avondale">Avondale</option>
<option value="Buckyeye">Buckeye</option>
<option value="Carefree">Carefree</option>
<option value="Cave Creek">Cave Creek</option>
<option value="Chandler">Chandler</option>
<option value="El Mirage">El Mirage</option>
<option value="Fountain Hills">Fountain Hills</option>
<option value="Gila Bend">Gila Bend</option>
<option value="Gilbert">Gilbert</option>
<option value="Glendale">Glendale</option>
<option value="Goodyear">Goodyear</option>
<option value="Guadalupe">Guadalupe</option>
<option value="Litchfield Park">Litchfield Park</option>
<option value="Mesa">Mesa</option>
<option value="Morristown">Morristown</option>
<option value="Paradise Valley">Paradise Valley</option>
<option value="Peoria">Peoria</option>
<option value="Phoenix">Phoenix</option>
<option value="Scottsdale">Scottsdale</option>
<option value="Sun City">Sun City</option>
<option value="Surprise">Surprise</option>
<option value="Tempe">Tempe</option>
<option value="Tolleson">Tolleson</option>
<option value="Wickenburg">Wickenburg</option>
<option value="Youngtown">Youngtown</option>
</select></td>
<td>
<input id="Search1" type="button" value="Search" onclick="validateOption1();" /></td>
<td>
<input id="Clear1" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
<tr>
<td colspan="6">If you're unsure about a field, leave it blank.</td>
</tr>
</table>
</form>

Old Pedant
09-12-2011, 11:17 PM
Code is working fine.

The way you call it is the culprit.

Because you call it from <input type="button"> there is *NOTHING* that causes the <form> to get submitted when the validation passes!!!

I *THINK* that what you meant to do was this:


<input type="submit" value="Search" onclick="return validateOption1();" />


As a minor point, you don't pass any argument to the function, so the function declaration probably really ought to be

function validateOption1( )

without the PropertyAddressSearch parameter.

The code *could* be written much simpler, but it should work, as is.

rnd me
09-12-2011, 11:21 PM
slight simplification:


var form = document.getElementById("PropertyAddressSearch");
if ( ! form.StreetNumber.value+
form.StreetName.value+
form.City.value ){
alert("Please enter a street number, street name, or city.");
form.StreetNumber.focus();
return false;
}

i don't know why i'm posting this...

Old Pedant
09-13-2011, 12:42 AM
Okay, even simpler.

Get rid of the onclick on the button. And put the check where it really belongs along with getting rid of the completely unneeded id's in the <form> fields and and and...


<form action="" onsubmit="return validateOption1(this);">
<input name="StreetNumber" type="text" />
<input name="StreetName" type="text" />
<select name="City">
...
</select>
...
<input type="submit" value="Search" />
</form>

And then write the function dirt simply:


function validateOption1(form)
{
if ( form.StreetNumber.value+form.StreetName.value+form.City.value == "" )
{
alert("Please enter a street number, street name, or city.");
form.StreetNumber.focus();
return false;
}
return true;
}

maryjane9110024
09-13-2011, 02:41 PM
Nope didn't work.


Code is working fine.

The way you call it is the culprit.

Because you call it from <input type="button"> there is *NOTHING* that causes the <form> to get submitted when the validation passes!!!

I *THINK* that what you meant to do was this:


<input type="submit" value="Search" onclick="return validateOption1();" />


As a minor point, you don't pass any argument to the function, so the function declaration probably really ought to be

function validateOption1( )

without the PropertyAddressSearch parameter.

The code *could* be written much simpler, but it should work, as is.

maryjane9110024
09-13-2011, 03:22 PM
I have 5 forms on this page and they all have:

<td>
<input id="Search3" type="button" value="Search" onclick="validateOption3();" /></td>
<td>
<input id="Clear3" type="button" value="Clear" onclick="this.form.reset();" /></td>

syntax for the submit and clear. Only ID's are different. Why is it that 2 out of the 5 forms work perfectly fine? These are HTML controls.

Old Pedant
09-13-2011, 09:04 PM
Then you have some cockpit error.

I create a simple *COMPLETE* test page using the code I showed and it works correctly:


<html>
<head>
<script>
function validateOption1(form)
{
if ( form.StreetNumber.value+form.StreetName.value+form.City.value == "" )
{
alert("Please enter a street number, street name, or city.");
form.StreetNumber.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="" onsubmit="return validateOption1(this);">
<input name="StreetNumber" type="text" />
<input name="StreetName" type="text" />
<select name="City">
<option>choose</option>
<option value="a"> city a </option>
<option value="b"> city b </option>
<option value="c"> city c </option>
<option value="d"> city d </option>
</select>
<input type="submit" value="Search" />
</form>
</body>
</html>

maryjane9110024
09-13-2011, 10:59 PM
But it doesn't work with multiple search buttons.

Old Pedant
09-14-2011, 12:11 AM
It's hard to guess what you mean when you won't show us your full HTML page.

But I'll try.

Here I have 3 <form>s. Two are nearly identical and even use the same validation function.

The middle one is different, on purpose, but uses a very similar validation function.

They all work.

How does this differ from what you have? Why don't you just give us the URL to your page so we can see it for ourselves?


<html>
<head>
<script>
function validateOption1(form)
{
if ( form.StreetNumber.value+form.StreetName.value+form.City.value == "" )
{
alert("Please enter a street number, street name, or city.");
form.StreetNumber.focus();
return false;
}
return true;
}
function validateOption2(form)
{
if ( form.zamboni.value+form.widget.value == "" )
{
alert("Please enter a zamboni and a widget.");
form.StreetNumber.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="" onsubmit="return validateOption1(this);">
<input name="StreetNumber" type="text" />
<input name="StreetName" type="text" />
<select name="City">
<option>choose</option>
<option value="a"> city a </option>
<option value="b"> city b </option>
<option value="c"> city c </option>
<option value="d"> city d </option>
</select>
<input type="submit" value="Search" />
</form>
<hr>
<form action="" onsubmit="return validateOption2(this);">
<input name="zamboni" type="text" />
<input name="widget" type="text" />
<input type="submit" value="Search" />
</form>
<hr>
<form action="" onsubmit="return validateOption1(this);">
<input name="StreetNumber" type="text" />
<input name="StreetName" type="text" />
<select name="City">
<option>choose</option>
<option value="x"> city x </option>
<option value="y"> city y </option>
<option value="z"> city z </option>
</select>
<input type="submit" value="Search" />
</form>

</body>
</html>

maryjane9110024
09-14-2011, 02:30 PM
I haven't figured out how to give you a url to my local pc yet. Working on that! ;)

The javascript file is over a 100 lines and theHTML is almost 200 lines. too much to post in a forum

maryjane9110024
09-14-2011, 04:21 PM
the page:

<%@ Page Title="" Language="C#" MasterPageFile="~/assessor.Master" AutoEventWireup="true" CodeBehind="residential_rental_property_search.aspx.cs" Inherits="WebApplication1.WebForm6" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageContent" runat="server">

<h1>Residential Rental Property Search</h1>
<p>Please choose one of the following five options:</p>
<form id="PropertyAddressSearch" action="">
<table>
<tr>
<td colspan="6"><b><span class="blue">Option One</span> Property Address Search:</b></td>
</tr>
<tr>
<td>Street Number</td>
<td>Street (Name Only)</td>
<td>City</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="StreetNumber" name="StreetNumber" type="text" /></td>
<td>
<input id="StreetName" name="StreetName" type="text" /></td>
<td>
<select id="City" name="City">
<option value="">- Please Select -</option>
<option value="I don't know">I don't know</option>
<option value="Avondale">Avondale</option>
<option value="Buckyeye">Buckeye</option>
<option value="Carefree">Carefree</option>
<option value="Cave Creek">Cave Creek</option>
<option value="Chandler">Chandler</option>
<option value="El Mirage">El Mirage</option>
<option value="Fountain Hills">Fountain Hills</option>
<option value="Gila Bend">Gila Bend</option>
<option value="Gilbert">Gilbert</option>
<option value="Glendale">Glendale</option>
<option value="Goodyear">Goodyear</option>
<option value="Guadalupe">Guadalupe</option>
<option value="Litchfield Park">Litchfield Park</option>
<option value="Mesa">Mesa</option>
<option value="Morristown">Morristown</option>
<option value="Paradise Valley">Paradise Valley</option>
<option value="Peoria">Peoria</option>
<option value="Phoenix">Phoenix</option>
<option value="Scottsdale">Scottsdale</option>
<option value="Sun City">Sun City</option>
<option value="Surprise">Surprise</option>
<option value="Tempe">Tempe</option>
<option value="Tolleson">Tolleson</option>
<option value="Wickenburg">Wickenburg</option>
<option value="Youngtown">Youngtown</option>
</select></td>
<td>
<input id="Search1" type="button" value="Search" onclick="validateOption1();" /></td>
<td>
<input id="Clear1" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
<tr>
<td colspan="6">If you're unsure about a field, leave it blank.</td>
</tr>
</table>
</form>

<form id="OwnersNameSearch" action="">
<table>
<tr>
<td colspan="5"><b><span class="blue">Option Two</span> Owner's Name Search:</b></td>
</tr>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="OwnersFirstName" name="OwnersFirstName" type="text" /></td>
<td>
<input id="OwnersLastName" name="OwnersLastName" type="text" /></td>
<td>
<input id="Search2" type="button" value="Search" onclick="validateOption2();" /></td>
<td>
<input id="Clear2" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td colspan="4"><a href="">Example</a></td>
</tr>
</table>
</form>


<form id="ParcelNumberSearch" action="">
<table>
<tr>
<td colspan="7"><b><span class="blue">Option Three</span> Parcel Number Search:</b></td>
</tr>
<tr>
<td>Book</td>
<td>Map</td>
<td>Parcel</td>
<td>Split</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="Book" name="Book" maxlength="3" size="4" type="text" /></td>
<td>
<input id="Map" name="Map" maxlength="2" size="4" type="text" /></td>
<td>
<input id="Parcel" name="Parcel" maxlength="3" size="4" type="text" /></td>
<td>
<input id="Split" name="Split" maxlength="1" size="4" type="text" /></td>
<td>
<input id="Search3" type="button" value="Search" onclick="validateOption3();" /></td>
<td>
<input id="Clear3" type="button" value="Clear" onclick="this.form.reset();" /></td>

<td><a href="">Example</a></td>
</tr>
<tr>
<td colspan="7">"Split" must be a letter, A-Z.</td>
</tr>
</table>
</form>


<form id="AgentsNameSearch" action="">
<table>
<tr>
<td colspan="5"><b><span class="blue">Option Four</span> Agent's Name Search:</b></td>
</tr>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="AgentsFirstName" name="AgentsFirstName" type="text" /></td>
<td>
<input id="AgentsLastName" name="AgentsLastName" type="text" /></td>
<td>
<input id="Search4" type="button" value="Search" onclick="validateOption4();" /></td>
<td>
<input id="Clear4" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
</table>
</form>



<form id="SubdivisionSearch" action="">
<table>
<tr>
<td colspan="4"><b><span class="blue">Option Five</span> Subdivision Search:</b></td>
</tr>
<tr>
<td>
<input id="SubdivisionName" name="SubdivisionName" type="text" /></td>
<td>
<input id="Search5" type="button" value="Search" onclick="validateOption5();" /></td>
<td>
<input id="Clear5" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
</table>
</form>


</asp:Content>


the js:

var alphaExp = /^[a-zA-Z]+$/;
var numExp = /^[0-9]+$/;

function validateOption1(PropertyAddressSearch) {

var StreetNumber = document.getElementById('StreetNumber');
var StreetName = document.getElementById('StreetName');
var City = document.getElementById('City');

// if (StreetNumber.value.length == 0) {
// if (StreetName.value.length == 0) {
// if (City.value.length == 0) {
// alert("Please enter a street number, street name, or city.");
// StreetNumber.focus();
// return false;
// }
// }
// }

if (StreetNumber.value.length == 0 && StreetName.value.length == 0 && City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}

if (StreetNumber.value.length != 0) {
if (StreetNumber.value.match(numExp)) {
}
else {
alert("Please enter a valid street number.");
StreetNumber.focus();
return false;
}
}


}

function validateOption2(OwnersNameSearch) {

var OwnersFirstName = document.getElementById('OwnersFirstName');
var OwnersLastName = document.getElementById('OwnersLastName');

if (OwnersFirstName.value.length == 0) {
alert("Please enter the owner's first name.");
OwnersFirstName.focus();
return false;
}

if (OwnersLastName.value.length == 0) {
alert("Please enter the owener's last name.");
OwnersLastName.focus();
return false;
}
}

function validateOption3(ParcelNumberSearch) {

var Book = document.getElementById('Book');
var Map = document.getElementById('Map');
var Parcel = document.getElementById('Parcel');
var Split = document.getElementById('Split');

if (Book.value.length == 0) {
alert("Please enter the book number.");
Book.focus();
return false;
}
if (Book.value.match(numExp)) {
if (Book.value.length < 3 || Book.value.length > 3) {
alert("Please enter a valid book number.");
Book.focus();
return false;
}
}
else {
alert("Please enter a valid book number.");
Book.focus();
return false;
}

if (Map.value.length == 0) {
alert("Please enter the map number.");
Map.focus();
return false;
}
if (Map.value.match(numExp)) {
if (Map.value.length < 2 || Map.value.length > 2) {
alert("Please enter a valid map number.");
Map.focus();
return false;
}
}
else {
alert("Please enter a valid map number.");
Map.focus();
return false;
}

if (Parcel.value.length == 0) {
alert("Please enter the parcel number.");
Parcel.focus();
return false;
}
if (Parcel.value.match(numExp)) {
if (Parcel.value.length < 3 || Parcel.value.length > 3) {
alert("Please enter a valid parcel number.");
Parcel.focus();
return false;
}
}
else {
alert("Please enter a valid parcel number.");
Parcel.focus();
return false;
}

if (Split.value.length != 0) {
if (Split.value.match(alphaExp)) {
if (Split.value.length != 1) {
alert("Please enter a valid split letter.");
Split.focus();
return false;
}
}
else {
alert("Please enter a valid split letter.");
Split.focus();
return false;
}
}

}

function validateOption4(AgentsNameSearch) {

var AgentsFirstName = document.getElementById('AgentsFirstName');
var AgentsLastName = document.getElementById('AgentsLastName');

if (AgentsFirstName.value.length == 0) {
alert("Please enter the agent's first name.");
AgentsFirstName.focus();
return false;
}

if (AgentsLastName.value.length == 0) {
alert("Please enter the agent's last name.");
AgentsLastName.focus();
return false;
}

}

function validateOption5(SubdivisionSearch) {

var SubdivisionName = document.getElementById('SubdivisionName');

if (SubdivisionName.value.length == 0) {
alert("Please enter the subdivision name.");
SubdivisionName.focus();
return false;
}

}

Old Pedant
09-14-2011, 08:58 PM
I told you your mistake way back in my post #7.

You have NO CODE WHATSOEVER in any of that page that will actually SUBMIT *ANY* of those <form>s!!!!

GO READ POST #7.

<input type="button"> *WILL NOT SUBMIT A FORM*. Period.

Old Pedant
09-14-2011, 09:40 PM
Oh, w.t.h.

Here. The JS code, fixed:


var alphaExp = /^[a-zA-Z]+$/;
var numExp = /^[0-9]+$/;

function validateOption1(form) {

var StreetNumber = form.StreetNumber;
var StreetName = form.StreetName;
var City = form.City;

if (StreetNumber.value.length == 0 && StreetName.value.length == 0 && City.value.length == 0) {
alert("Please enter a street number, street name, or city.");
StreetNumber.focus();
return false;
}

if (StreetNumber.value.length != 0) {
if (StreetNumber.value.match(numExp)) {
}
else {
alert("Please enter a valid street number.");
StreetNumber.focus();
return false;
}
}
return true;

}

function validateOption2(form) {

var OwnersFirstName = form.OwnersFirstName;
var OwnersLastName = form.OwnersLastName;

if (OwnersFirstName.value.length == 0) {
alert("Please enter the owner's first name.");
OwnersFirstName.focus();
return false;
}

if (OwnersLastName.value.length == 0) {
alert("Please enter the owener's last name.");
OwnersLastName.focus();
return false;
}
return true;
}

function validateOption3(form) {

var Book = form.Book;
var Map = form.Map;
var Parcel = form.Parcel;
var Split = form.Split;

if (Book.value.length == 0) {
alert("Please enter the book number.");
Book.focus();
return false;
}
if (Book.value.match(numExp)) {
if (Book.value.length < 3 || Book.value.length > 3) {
alert("Please enter a valid book number.");
Book.focus();
return false;
}
}
else {
alert("Please enter a valid book number.");
Book.focus();
return false;
}

if (Map.value.length == 0) {
alert("Please enter the map number.");
Map.focus();
return false;
}
if (Map.value.match(numExp)) {
if (Map.value.length < 2 || Map.value.length > 2) {
alert("Please enter a valid map number.");
Map.focus();
return false;
}
}
else {
alert("Please enter a valid map number.");
Map.focus();
return false;
}

if (Parcel.value.length == 0) {
alert("Please enter the parcel number.");
Parcel.focus();
return false;
}
if (Parcel.value.match(numExp)) {
if (Parcel.value.length < 3 || Parcel.value.length > 3) {
alert("Please enter a valid parcel number.");
Parcel.focus();
return false;
}
}
else {
alert("Please enter a valid parcel number.");
Parcel.focus();
return false;
}

if (Split.value.length != 0) {
if (Split.value.match(alphaExp)) {
if (Split.value.length != 1) {
alert("Please enter a valid split letter.");
Split.focus();
return false;
}
}
else {
alert("Please enter a valid split letter.");
Split.focus();
return false;
}
}
return true;
}

function validateOption4(form) {

var AgentsFirstName = form.AgentsFirstName;
var AgentsLastName = form.AgentsLastName;

if (AgentsFirstName.value.length == 0) {
alert("Please enter the agent's first name.");
AgentsFirstName.focus();
return false;
}

if (AgentsLastName.value.length == 0) {
alert("Please enter the agent's last name.");
AgentsLastName.focus();
return false;
}
return true;
}

function validateOption5(form) {

var SubdivisionName = form.SubdivisionName;

if (SubdivisionName.value.length == 0) {
alert("Please enter the subdivision name.");
SubdivisionName.focus();
return false;
}
return true;
}

Old Pedant
09-14-2011, 09:44 PM
And then then HTML code, fixed:


<h1>Residential Rental Property Search</h1>
<p>Please choose one of the following five options:</p>
<form id="PropertyAddressSearch" action="" onsubmit="return validateOption1(this);">
<table>
<tr>
<td colspan="6"><b><span class="blue">Option One</span> Property Address Search:</b></td>
</tr>
<tr>
<td>Street Number</td>
<td>Street (Name Only)</td>
<td>City</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="StreetNumber" name="StreetNumber" type="text" /></td>
<td>
<input id="StreetName" name="StreetName" type="text" /></td>
<td>
<select id="City" name="City">
<option value="">- Please Select -</option>
<option value="I don't know">I don't know</option>
<option value="Avondale">Avondale</option>
<option value="Buckyeye">Buckeye</option>
<option value="Carefree">Carefree</option>
<option value="Cave Creek">Cave Creek</option>
<option value="Chandler">Chandler</option>
<option value="El Mirage">El Mirage</option>
<option value="Fountain Hills">Fountain Hills</option>
<option value="Gila Bend">Gila Bend</option>
<option value="Gilbert">Gilbert</option>
<option value="Glendale">Glendale</option>
<option value="Goodyear">Goodyear</option>
<option value="Guadalupe">Guadalupe</option>
<option value="Litchfield Park">Litchfield Park</option>
<option value="Mesa">Mesa</option>
<option value="Morristown">Morristown</option>
<option value="Paradise Valley">Paradise Valley</option>
<option value="Peoria">Peoria</option>
<option value="Phoenix">Phoenix</option>
<option value="Scottsdale">Scottsdale</option>
<option value="Sun City">Sun City</option>
<option value="Surprise">Surprise</option>
<option value="Tempe">Tempe</option>
<option value="Tolleson">Tolleson</option>
<option value="Wickenburg">Wickenburg</option>
<option value="Youngtown">Youngtown</option>
</select></td>
<td>
<input id="Search1" type="submit" value="Search" /></td>
<td>
<input id="Clear1" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
<tr>
<td colspan="6">If you're unsure about a field, leave it blank.</td>
</tr>
</table>
</form>

<form id="OwnersNameSearch" action="" onsubmit="return validateOption2(this);">
<table>
<tr>
<td colspan="5"><b><span class="blue">Option Two</span> Owner's Name Search:</b></td>
</tr>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="OwnersFirstName" name="OwnersFirstName" type="text" /></td>
<td>
<input id="OwnersLastName" name="OwnersLastName" type="text" /></td>
<td>
<input id="Search2" type="submit" value="Search" /></td>
<td>
<input id="Clear2" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td colspan="4"><a href="">Example</a></td>
</tr>
</table>
</form>


<form id="ParcelNumberSearch" action="" onsubmit="return validateOption3(this);">
<table>
<tr>
<td colspan="7"><b><span class="blue">Option Three</span> Parcel Number Search:</b></td>
</tr>
<tr>
<td>Book</td>
<td>Map</td>
<td>Parcel</td>
<td>Split</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="Book" name="Book" maxlength="3" size="4" type="text" /></td>
<td>
<input id="Map" name="Map" maxlength="2" size="4" type="text" /></td>
<td>
<input id="Parcel" name="Parcel" maxlength="3" size="4" type="text" /></td>
<td>
<input id="Split" name="Split" maxlength="1" size="4" type="text" /></td>
<td>
<input id="Search3" type="submit" value="Search" /></td>
<td>
<input id="Clear3" type="button" value="Clear" onclick="this.form.reset();" /></td>

<td><a href="">Example</a></td>
</tr>
<tr>
<td colspan="7">"Split" must be a letter, A-Z.</td>
</tr>
</table>
</form>


<form id="AgentsNameSearch" action="" onsubmit="return validateOption4(this);">
<table>
<tr>
<td colspan="5"><b><span class="blue">Option Four</span> Agent's Name Search:</b></td>
</tr>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input id="AgentsFirstName" name="AgentsFirstName" type="text" /></td>
<td>
<input id="AgentsLastName" name="AgentsLastName" type="text" /></td>
<td>
<input id="Search4" type="submit" value="Search" /></td>
<td>
<input id="Clear4" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
</table>
</form>



<form id="SubdivisionSearch" action="" onsubmit="return validateOption5(this);">
<table>
<tr>
<td colspan="4"><b><span class="blue">Option Five</span> Subdivision Search:</b></td>
</tr>
<tr>
<td>
<input id="SubdivisionName" name="SubdivisionName" type="text" /></td>
<td>
<input id="Search5" type="submit" value="Search" /></td>
<td>
<input id="Clear5" type="button" value="Clear" onclick="this.form.reset();" /></td>
<td><a href="">Example</a></td>
</tr>
</table>
</form>


Notice that the validation is moved to the onsubmit of each <form>. Notice that we pass a reference to the <form> to each validation routine. Notice that we do *NOT* use document.getElementById *ANY PLACE* in the code any more.

Notice that the submit buttons are now type="submit" instead of type="button".

All very standard practice. All simpler that what you were doing.

maryjane9110024
09-15-2011, 03:21 PM
BULL****!!!! b/c I literally copy and pasted code from ONE page to ANOTHER page and that other page works perfectly fine! You don't understand that two other submits work on this page only THREE of the FIVE don't work?? Do you not understand the fact that there are like 20 forms for this site and I'VE DONE THEM ALL THE SAME WAY AND THEY ALL WORK PERFECTLY FINE!??

You're dumb. B/c <input type="button"> DOES SUBMIT with an onclick property. So can someone who actually knows something about HTML controls answer instead of you? B/c 1 i dont like your attitude and 2 you obviously DONT listen to me with your caps and *asterisks *... what does that mean anyway?


I told you your mistake way back in my post #7.

You have NO CODE WHATSOEVER in any of that page that will actually SUBMIT *ANY* of those <form>s!!!!

GO READ POST #7.

<input type="button"> *WILL NOT SUBMIT A FORM*. Period.

maryjane9110024
09-15-2011, 03:25 PM
OH and btw....

var StreetNumber = form.StreetNumber;
var StreetName = form.StreetName;
var City = form.City;


won't work... i suppose this is what i get for asking people questions in forums when they constantly give a 1/2 fast answer and try to rewrite my entire code in the process AND when i change my code to theirs it still doesnt work.. GG

don't bother replying old pendant b/c i'm done here. your a jerk.

xelawho
09-15-2011, 03:28 PM
So can someone who actually knows something about HTML controls answer instead of you?

oh, yeah. because you insult the only person who goes through your code line by line trying to help you. I'm sure they'll be lining up...

maryjane9110024
09-15-2011, 03:30 PM
i did that it didnt work YOU ARE WRONG!!!


I told you your mistake way back in my post #7.

You have NO CODE WHATSOEVER in any of that page that will actually SUBMIT *ANY* of those <form>s!!!!

GO READ POST #7.

<input type="button"> *WILL NOT SUBMIT A FORM*. Period.



NOW I'M DONE!

maryjane9110024
09-15-2011, 03:33 PM
His code is wrong it didnt work. PERIOD
So his help means nothing when it doesn't even work and he wont even listen to what i am trying to say. You can go through all the lines of code you want and take all the time in the world. the fact it works on his machine and not mine means nothing and does nothing for me. i'll figure it out myself like EVERY single other problem i have asked for help on the forums and have gotten no where.


oh, yeah. because you insult the only person who goes through your code line by line trying to help you. I'm sure they'll be lining up...

maryjane9110024
09-15-2011, 03:36 PM
Good bye forums!

Old Pedant
09-15-2011, 04:41 PM
Just to prove that "mary jane" doesn't have the foggiest idea what she (if it is a "she"...sounds more like a teenage boy...eh...or maybe a teenage girl) has no idea what she is talking about:

http://www.plopon.com/maryJane.html

You can click on the VIEW menu of your browser and then the SOURCE or PAGE SOURCE menu item to see that the code there is identical to what I gave her, with only a couple of (irrelevant) changes:
(1) I gave each <form> an action= to point to an ASP page that simply dumps out all the values sent to it.
(2) For the second <form>, just to prove a point, I omitted the id= of the <form> *and* made only that <form> have method="post" (and you can see the results if you enter data into first form 1 and hit search, hit your BACK button, then enter data into form 2 and hit search).

************

I suspect that part of the problem is that "Mary Jane" never did show us her *TRUE* code.

If you look at the first line of her *supposed* HTML page, you see this:

<%@ Page Title="" Language="C#" MasterPageFile="~/assessor.Master" AutoEventWireup="true" CodeBehind="residential_rental_property_search.aspx.cs" Inherits="WebApplication1.WebForm6" %>

So this is *actually* an ASP.NET page.

And yet NO PLACE in the page is she(?) using ASP.NET controls!

EACH AND EVERY ONE OF THOSE form fields should really be something like <asp:textbox ...> and all of the <form>s should declare themselves as runat="server".

It probably is true that she uses type="button", because she also has (see that first line) AutoEventWireup="true". In ASP.NET, that means that the ASP.NET processor will automatically add event handlers to your controls that will cause the <form> to post back to the server. Or, at least, that WOULD be true if you coded something like <asp:button ... instead of <input type="buttonm" ....

So she has some weird hodge-podge of ASP.NET and HTML code and quite frankly it's a real surprise to me that it works at all.

But since she is clearly way out of her depth with the HTML, who knows how badly underwater she is when it comes to ASP.NET?

rickself3
04-29-2012, 06:34 PM
I really like going through the older posts. It can be both learning AND entertaining, but for the responders, it has to be frustrating as all hell.
Well handled, I must say!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum