A checkbox will be created according to the query. I want to validate the checkbox before submitting the form.
I have used that check all开发者_Go百科 and uncheck all using javascript so I used the attribute id
in an array:
<input type="checkbox" name="playlist[]" id="playlist" value="<?php echo $filmpath; ?>"/>
I used the validation code as
//enter code here
function chkvalidate()
{
//enter code here
if ( document.modifyform.playlist.checked == false )
{
//enter code here
alert( "Please check the Terms & Conditions box." );
//enter code here
valid = false;
//enter code here
}
}
This code is not working.
Are you using the correct capitalisation in your code? JavaScript is case sensitive, and I believe that if you change modifyform
to modifyForm
your code will likely execute properly.
That being said, it is a good idea to use camelCase as a naming convention for your variable and function names. It is not required, but it makes for more consistent and easier to read code. Additionally, since any respectable third party library will be using camelCase, it will make it much easier for yourself if you use that convention as well, otherwise you will have multiple naming conventions throughout your source code, and that is simply not maintainable.
You need document.forms.modifyform.playlist.checked
instead to access the form (by name or id) in the DOM. With your existing code, Javascript is trying to access a property called modifyform
on the document
object, which does not exist.
For reference, documentation.form
shows the list of properties you can call on the form
object.
精彩评论