Ok, I am constructing the back-end for a shopping cart in PHP. I’m not super familiar with JS and am having some problems using it.
Here is the situation:
I have a .js file containing all the JS function used throught the admin: admin.js
All my php runs through a fuse box that is index.php. So as far as the user knows everything takes place on one page, however depending on the fuse the php will include the necessary pages. So I load the js into the head of index.php.
Here is where my problem lies. Only the last function in the .js works. None of the others are recognized. I’m sure this is a nooby problem, something simple to change. I’ve searched the net quite a bit and have seen things about JS only loading last function defined or something.
Any help will be appreciated. Files to follow:
admin.js
function validate_form_top ( )
{
valid = true;
if ( document.search_form_top.m.value == "" )
{
alert ( "Please Choose a Category" );
valid = false;
}else if ( document.search_form_top.search.value == "" )
{
alert ( "Please Enter Search Criteria" );
valid = false;
}
return valid;
}
function change_status()
{
document.add_product.change.value = 'yes';
document.add_product.submit();
}
function cat_confirm_entry()
{
input_box=confirm("Are you sure you want to delete the category '<? echo($catName)?>', all <? echo($numSubCats) ?> sub-categories, and all <? echo($j) ?> products?");
if (input_box==true)
{
// Output when OK is clicked
document.deleteCat.submit();
}
else
{
return false;
}
}
function validate_form ( )
{
valid = true;
if ( document.search_form.m.value == "" )
{
alert ( "Please Choose a Category" );
valid = false;
}else if ( document.search_form.search.value == "" )
{
alert ( "Please Enter Search Criteria" );
valid = false;
}
return valid;
}
function sub_confirm_entry()
{
input_box=confirm("Are you sure you want to delete the sub-category '<? echo($catName)?>' and all <? echo($j) ?> products?");
if (input_box==true)
{
// Output when OK is clicked
document.deleteCat.submit();
}
else
{
return false;
}
}
function validateproduct ()
{
valid = true;
if ( document.add_product.maincatID.value == "" )
{
alert ( "Please Choose a Category" );
valid = false;
}else if(document.add_product.subcatID.value == "")
{
alert ( "Please Choose a Sub-Category" );
valid = false;
}else if(document.add_product.prodName.value == "")
{
alert ( "Please Enter a Product Name" );
valid = false;
}else if(document.add_product.prodPartNum.value == "")
{
alert ( "Please Enter a Part #" );
valid = false;
}else if(document.add_product.retailPrice.value == "")
{
alert ( "Please Enter a Retail Price" );
valid = false;
}else if(document.add_product.dealerPrice.value == "")
{
alert ( "Please Enter a Dealer Price" );
valid = false;
}else if(document.add_product.oemPrice.value == "")
{
alert ( "Please Enter a OEM Price" );
valid = false;
}
if(valid==true;){
document.add_product.m.value = 'editProduct';
document.add_product.submit();
}
}
What a mess…I know.
Also, should I include this .js file at the end of the html since parts of it are generated by the PHP?
Thanks for the help!