Reputation: 659
I am using a software called Optiview to make a form for accounting purpose. I have a signature field that looks like a button but has different properties. When the person who has to sign that form press that button, it automatically opens a dialog giving to the user the opportunity to agree with the info that is on the form. If the user accept it, it will stamp the user name, date and time it was accepted. What I am trying to do is validate if that button has info or not before submitting the form, but code below always returned me empty("") or undefined, even if the field has been stamped with the signature. If more details are required please let me know.
Code: always return empty
var signature = $(Reviewer).attr('id');
var signvalue = $(signature).text();
if (signvalue == "")
{
CSClient.alert("Please sign before submitting invoice!")
return false;
}
Code: always return undefined
var signature = $(Reviewer).attr('id');
var signvalue = $(signature).val();
if (signvalue === undefined)
{
CSClient.alert("Please sign before submitting invoice!")
return false;
}
Any help will be really appreciated
PD: I am new using jquery/javascript, so please try to explain me with more details as possible.
Thank you
Upvotes: 0
Views: 338
Reputation: 73
I believe that you want to use .val() instead of .text().
var signature = $(Signature).attr('id');
var signvalue = $(signature).val();
if (signvalue == "")
{
CSClient.alert("Please sign before submitting invoice!")
return false;
}
See this question/answer for some more details.
Also I believe you want to use "===" instead of "==", but someone else can correct me if I'm wrong.
Edit: With clarification on the original post:
I think this should work for what you're trying to do:
var signature = $("#Reviewer").val();
if (signature === "") {
CSClient.alert("Please sign before submitting invoice!")
return false;
}
Upvotes: 2