Jump to content

[SOLVED] javascript validation issue


ainoy31

Recommended Posts

Hello-

 

I am having an issue with my javascript validation on my form.  Here is the process of my form.  On the main form, I have a button with the user can select to add a rating attribute so they can add a phone service.  Once that is completed, they are redirected back to the main page that now has a drop down menu to select a phone service.  If they try to save and don't select a phone service, the javascript alerts an error message that they need to select one.  The user are allow to go back to the rating attribute page and uncheck the rating attribute.  This will remove the added phone service and redirect the user back to the main form.  To complete the process, they need to click on save.  This is my issue with the javascript.  It does not save and returns an error message of:  Error:  'document.edit_product.primary_rating_product.value' is null or not an object.  How can I avoid it from checking to see is a phone service has been selected if even there is no phone service to choose from?  Thank you.  Here is my javascript code:

 

function validateProductForm()
{
if(document.edit_product.primary_rating_product.value == 0)
{
errmsg += 'You must select a Primary Rating Product\n';
}
if( errmsg != '' )
{
alert( errmsg );
}
else
{
window.document.edit_product.submit();
}
function alertuser(field,msg) 
{
alert(msg);
field.focus();
}

}

 

The drop down menu:

<select name="primary_rating_product" class="smaller">
<option value="<?=$data->productItemId?>"><?=$data->name?></option>
</select>

 

Hope this makes sense.  Much appreciation.

Link to comment
https://forums.phpfreaks.com/topic/121735-solved-javascript-validation-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.