Cross Vander
Cross Vander

Reputation: 2157

Validation with Javascript not working

I have javascript code at here:

Demo

But the jsfiddle said it has error :

{"error": "Shell form does not validate{'html_initial_name': u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at 0xa2ea90c>, 'html_name': 'js_lib', 'html_initial_id': u'initial-id_js_lib', 'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0xa2ef70c>, 'help_text': '', 'name': 'js_lib'}{'html_initial_name': u'initial-js_wrap', 'form': <mooshell.forms.ShellForm object at 0xa2ea90c>, 'html_name': 'js_wrap', 'html_initial_id': u'initial-id_js_wrap', 'label': u'Js wrap', 'field': <django.forms.fields.TypedChoiceField object at 0xa2ef12c>, 'help_text': '', 'name': 'js_wrap'}"}

I have tried at my main program and this JS doesn't work, so I try at jsfiddle then I got that result. What happened with my JS? because I have same JS (different name of form and textbox) but it works perfectly..

Upvotes: 0

Views: 58

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

multiple problems

  1. script was onload
  2. validate method name and an element had the same id alasan
  3. textarea had a default value (one space)

Fixed Demo:

function validate(myform)
{
    if(document.myform.alasan.value == "")
    {

        alert("Alasan harus diisi");
        document.myform.alasan.focus();
        return false;
    }
    else
    {
        return true;
    }
}

Upvotes: 2

Related Questions