php - Disabling button depending if variable is empty or NULL -



php - Disabling button depending if variable is empty or NULL -

i have several input fields , using ajax assign values php variables. in javascript code have function savethem stores values. @ end there button store values in mysql database. php, how can disable button if 1 of variables happens empty or null ? mockup site

select: function savethem() { var name = $.trim($("#name").val()); var age = $.trim($("#age").val()); var phone = $.trim($("#phone").val()); var email = $.trim($("#email").val()); var job = $.trim($("#job").val()); var hobby = $.trim($("#hobby").val()); var datastring = 'name='+name+'&age='+age+'&phone='+phone+'&email='+email+'&job='+job+'&hobby='+hobby; $.ajax({ type: "post", url: 'posting.php', data: datastring, datatype: "html", success: function(data) { /*if(data.response){ alert(data.message); }*/ $("#inputresult").html(data); } }); }

php

$name = (isset($_post['name'])) ? strip_tags($_post['name']) : null; $age = (isset($_post['age'])) ? strip_tags($_post['age']) : null; $phone = (isset($_post['phone'])) ? strip_tags($_post['phone']) : null; $email = (isset($_post['email'])) ? strip_tags($_post['email']) : null; $job = (isset($_post['job'])) ? strip_tags($_post['job']) : null; $hobby = (isset($_post['hobby'])) ? strip_tags($_post['hobby']) : null; echo ('<br>'.$name.'<br>'.$age.'<br>'.$phone.'<br>'.$email.'<br>'.$job.'<br>'.$hobby);

you can disable button in javascript if of variable happens null or empty.

if($("#name").val() == '' || $("#age").val() == '' || .... on ) { $("#buttonid").attr('disabled',true); } else { $("#buttonid").attr('disabled',false); } var datastring = 'name='+name+'&age='+age+'&phone='+phone+'&email='+email+'&job='+job+'&hobby='+hobby;

php

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -