0

I have 2 simple JS function one checks values of 2 input fields and triggers the other function Here is the code

function ValidateForm()
    {
    var name = document.getElementById('fullname').value;
     var email = document.getElementById('email').value;
     if(name.value= '' || email.value='')
     {
     alert('fields Empty');
     }
     else
     {
     UpdateRecord();
     }

    }


    function UpdateRecord()
    {
    var Qact = getQueryVariable('ACT');
        if(Qact==2){

            var picture= document.getElementById('myPic').src;
            activity.setUpdates(name,email,picture);
            }
            else
            {
            activity.CheckEmail(name,email);
            }
        }

HTML

<button onClick="ValidateForm();" data-role="button" >Register</button>

if I call UpdateRecord() on button click it works fine but when i use ValidateForm() nothing works. The firefox debugger don't even go to the ValidateForm() Function

2
  • you are asigning value , not matching valuename.value= '' use==. Commented Apr 17, 2014 at 6:09
  • Thanks for the comment reiterating my answer ;) Commented Apr 17, 2014 at 6:10

3 Answers 3

6
if(name.value= '' || email.value='') 

should be

if(name === '' || email === '')
Sign up to request clarification or add additional context in comments.

4 Comments

thanks it worked but now its calling UpdateRecord() even when input fields are empty . . .
See my update. You were trying to reference element.value.value
It didn't worked for me , but this did if(name.value == null || email.value == null) but you pointed out the basic mistake thanks :-)
No, name.value would be null because you were doing document.getElementById('foo').value <-- notice the .value. Then you were looking at the .value again. So of course name.value.value would be undefined, or falsy null.
0
if(name.value== '' || email.value=='')
{
    alert('fields Empty');
}
else
{
    UpdateRecord();
}

Comments

0

Try this to compare values:

if(name.value == '' || email.value == '')
{
    alert('fields Empty');
}
else
{
    UpdateRecord();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.