Click to See Complete Forum and Search --> : alert user in form


d333mu
04-19-2006, 12:05 PM
hi am trying to find do a alert code on this form, as user enters all the data in form before pressing submit an alert box should appear, and tells the user
'we have one dog that matches the users choice'

here is the form what i want the code in i have done the alert box but it keeps on coming up as i go on to the form

{
alert('You want bully');}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<script type="text/javascript">

var dogPhoto = "";
function displayPhoto(nPhoto){

if (nPhoto == ""){return}
var currPhoto = nPhoto;
if (dogPhoto != ""){dogPhoto.close()}
dogPhoto = window.open('','','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,hei ght=350,left = 262,top = 134');
dogPhoto.document.open();
var imgStr = "<img src="+currPhoto+">"
dogPhoto.document.write(imgStr);
dogPhoto.document.close();
var imgStr = "<img src="+currPhoto+">"
dogPhoto.document.write(imgStr);
dogPhoto.document.write("<br><input type='button' value='Close me' onclick='self.close ()'>");


}


var dogs = [];
dogs[0] = ['s','s','l',false,'bully.jpg','Bully'];
dogs[1] = ['s','s','h',true,'rex.jpg','Rex'];
dogs[2] = ['s','l','l',true,'daisy.jpg','Daisy'];
dogs[3] = ['m','s','h',true,'dot.jpg','Dot']; // same as liquorice
dogs[4] = ['l','l','l',true,'sam.jpg','Sam'];
dogs[5] = ['l','s','h',true,'pip.jpg','Pip'];
dogs[6] = ['s','l','l',false,'cyril.jpg','Cyril'];
dogs[7] = ['l','s','l',true,'bones.jpg','Bones'];
dogs[8] = ['m','s','h',true,'liquorice.jpg','Liquorice']; //same as dot
dogs[9] = ['l','s','h',false,'fang.jpg','Fang'];


function buildList(nName,nPhoto){

var nOption = document.createElement('option');
var isData = document.createTextNode(nName);
nOption.setAttribute('value',nPhoto);
nOption.appendChild(isData);
document.forms[1]['matched'].appendChild(nOption);
}

function chooseDog(nForm){

if (dogPhoto != ""){dogPhoto.close()}
document.forms[1]['matched'].options.length = 1;

var nSize = nForm['size'].value;
var nCoat = nForm['coat'].value;
var nEnergy = nForm['energy'].value;

if (nSize == "" || nCoat == "" || nEnergy == "")
{alert('Select from all lists'); return}

var nChild = false;
if (document.getElementsByName('child')[0].checked){nChild = true}

var n = 0;

for (i=0; i<dogs.length; i++)
{
if (nSize == dogs[i][0] && nCoat == dogs[i][1] && nEnergy == dogs[i][2] && nChild == dogs[i][3])
{
buildList(dogs[i][5],dogs[i][4])
}
}
if (document.forms[1]['matched'].length == 1)
{alert('No Matches Found')}
}

</script>
</head>
<body>

<form>
<fieldset align='center' style='font-size:12pt;width:625px;padding:5px'>
<legend style='font-size:14pt;color:darkblue;padding:3px'> Choose a dog</legend>

<label>Select its size
<select name="size">
<option value=""> Choose </option>
<option value="l">Large </option>
<option value="m">Medium </option>
<option value="s">Small </option>
<option value="d">Any </option>
</select>
</label>

&nbsp;&nbsp

<label> Select its coat
<select name="coat">
<option value=""> Choose </option>
<option value="s">Short </option>
<option value="l">Long </option>
<option value="d">Any </option>
</select>
</label>

&nbsp;&nbsp

<label> Select its level
<select name="energy">
<option value=""> Choose </option>
<option value="h">High Energy </option>
<option value="l">Low Energy </option>
<option value="d">Any </option>
</select>
</label>

<br><br>

<label> Should the dog be good with children? </label>
<label> Yes <input type="radio" NAME="child"> </label>
<label> No <input type="radio" NAME="child" checked> </label>

<br><br>

<input type="button" value="Submit" onclick="chooseDog(this.form)">
&nbsp;&nbsp;
<INPUT TYPE=reset>
</fieldset>
</form>

<form>
<fieldset align='center' style='font-size:12pt;width:625px;padding:5px'>
<legend style='font-size:14pt;color:darkblue;padding:3px'> Matched Dogs</legend>

<select name='matched' onchange="displayPhoto(this.value)">
<option value=""> Select to View a Photo </option>
</select>
</fieldset>



</form>

</body>
</html>