Forum Moderators: open

Message Too Old, No Replies

selectedIndex has no properties

Identical code... works in one, not other

         

ksdfla

3:06 pm on May 16, 2005 (gmt 0)

10+ Year Member



Hi,

I've duplicated the code from one page/website to another page/website. The code works without any errors on the original site, but on the second site I get: 'document.recipes.vendor1 has no properties'

I'm totally stumped since the codes are identical and it's working on the other site. I've re-copied, and that didn't help. Any ideas?

Thanks!


<script language="JavaScript" type="text/JavaScript">
<!-- Required Form Fields Script -->
<!-- Hide from older browsers
function validateRecipes() {
if (document.recipes.vendor1.selectedIndex == 0) {
alert("Please select a vendor.");
document.recipes.vendor1.focus;
return false;
}
if (document.recipes.category1.selectedIndex == 0) {
alert("Please select a category.");
document.recipes.category1.focus;
return false;
}

if (document.recipes.imagepath.value.length < 1) {
alert ("Please enter an image path or enter the default gif.");
document.recipes.imagepath.select();
document.recipes.imagepath.focus();
return false;
}
if (document.recipes.title.value.length < 1) {
alert ("Please select a title.");
document.recipes.title.select();
document.recipes.title.focus();
return false;
}
if (document.recipes.ingredients.value.length < 1) {
alert ("Please enter the ingredients.");
document.recipes.ingredients.select();
document.recipes.ingredients.focus();
return false;
}
if (document.recipes.directions.value.length < 1) {
alert ("Please enter the directions.");
document.recipes.directions.select();
document.recipes.directions.focus();
return false;
}
if (document.recipes.contributor.value.length < 1) {
alert ("Please enter a contributor.");
document.recipes.contributor.select();
document.recipes.contributor.focus();
return false;
}
return true;
}
// End Hiding -->
</script>
<table width="100%" border="0" cellspacing="6" cellpadding="0">
<tr>
<td width="101%" bgcolor="#F0F0F0"><img src="/images/clearpixel.gif" width="1" height="1"></td>
</tr>
<tr>
<td><h3>BTF Admin: Add Recipe</h3>

<form name="recipes" method="post" action="/recipes/addrecipe_proc.php" onSubmit="return validateRecipes();">
<table width="600" border="0" cellpadding="6">

<?php

// connect to ecom database
require_once ("../../Connections/mysql_connect2.php");

// create sql statement
// select vendor names for drop-down list

// create sql statement
// make vendor pull-down menus from recipe_vendor table
$query = "SELECT * FROM recipe_vendor ORDER BY vendor ASC";
$result = @mysql_query ($query);
$pulldown = '<option>0</option>';
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
$pulldown .= "<option value=\"{$row['vendorID']}\">{$row['vendor']}</option>\n";
}
?>

<tr>
<td align="right">Vendor 1:</td>
<td><select name="vendor1"><?php echo $pulldown;?></select></td>
</tr>
<tr>
<td align="right">Vendor 2:</td>
<td><select name="vendor2"><?php echo $pulldown;?></select>
(optional)</td>
</tr>
<tr>
<td align="right">Vendor 3:</td>
<td><select name="vendor3"><?php echo $pulldown;?></select>
(optional)</td>
</tr>

<?php

// create sql statement
// make category pull-down menus from recipe_category table
$query = "SELECT * FROM recipe_category ORDER BY category ASC";
$result = @mysql_query ($query);
$pulldown = '<option>0</option>';

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
$pulldown .= "<option value=\"{$row['categoryID']}\">{$row['category']}</option>\n";
}
?>
<tr>
<td align="right">Category 1:</td>
<td><select name="category1"><?php echo $pulldown;?></select></td>
</tr>
<tr>
<td align="right">Category 2:</td>
<td><select name="category2"><?php echo $pulldown;?></select>
(optional)</td>
</tr>
<tr>
<td align="right">Category 3:</td>
<td><select name="category3"><?php echo $pulldown;?></select>
(optional)</td>
</tr>
<tr>
<td align="right">Image Path:</td>
<td><input name="imagepath" type="text" id="imagepath" value="recipeimages/clearpixel.gif" size="50"></td>
</tr>
<tr>
<td align="right">Title:</td>
<td><input name="title" type="text" id="title" size="50"></td>
</tr>
<tr>
<td align="right" valign="top">Ingredients:</td>
<td><textarea name="ingredients" cols="50" rows="10" id="ingredients"></textarea></td>
</tr>
<tr>
<td align="right" valign="top">Directions:</td>
<td><textarea name="directions" cols="50" rows="10" id="directions"></textarea></td>
</tr>
<tr>
<td align="right">Contributor:</td>
<td><input name="contributor" type="text" id="contributor" size="50"></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>

natty

3:09 pm on May 16, 2005 (gmt 0)

10+ Year Member



hi there,

could always try to put a top option of
<option value="">Please select</option>
and see if that does the trick. but in the html not the php..
cant say i can see any problem with your code tho, but then my php is not so hot..

hth

nat

ksdfla

3:29 pm on May 16, 2005 (gmt 0)

10+ Year Member



Hi,

Thanks. It's been a long time since I set up the original form and I'm pretty sure that due to the way in which the php integrates with it, that I wouldn't be able to make that change.

It's so hard to figure out why this works on site a, but not on site b. Site a is closing, so I have to get this working on site b.

Thanks again...

ajkimoto

4:31 pm on May 16, 2005 (gmt 0)

10+ Year Member



ksdfla,

How about posting the generated html for the select element. It sounds to me like something is going wrong in the creation of the html, which would result in js giving you a 'no properties' error.

ajkimoto

ksdfla

4:32 pm on May 16, 2005 (gmt 0)

10+ Year Member



Finally got it to work. I changed the name of the form and the function name and it works now. Since the script is identical to the working one and the only thing different is the navigation, I thought there might be some sort of name conflict.

Anyway, changing those names took care of the error message and I get the javascript alerts as I should if options aren't selected.

ksd

ksdfla

4:50 pm on May 16, 2005 (gmt 0)

10+ Year Member



Sorry, ajkimoto, I posted before I saw your response. But apparently you were right on target! Thanks!

Regards,
ksd