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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.