How to check the value of a field

Hello everyone,

I have been trying to find the value of a given field so that I write a condition. Here a sample of the code:


//code starts here
cur_frm.cscript.custom_validate = function(doc){

    if (doc.getElementsByName('type_of_id')[0].value == 'Passport') {
        if (doc.id_number.length < 9){
            msgprint ("The ID number cannot be less than 9 characters long");
            validated = false;
        }

    }
}

// code ends here.


Basically what I want to achieve is this:

If the user selects 'Passport' as the type of id then the 'id_number' field must be checked for the length (in this case it shouldn't be less than 9 characters).

I doubt that my syntax is correct, I will greatly appreciate help or suggestion.


Kind regards,
Kat



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
To access the value of a form field, don't use getElementByName, instead use doc.type_of_id

On 20-Dec-2013, at 8:23 PM, Kat wrote:

Hello everyone,

I have been trying to find the value of a given field so that I write a condition. Here a sample of the code:


//code starts here
cur_frm.cscript.custom_validate = function(doc){

    if (doc.getElementsByName('type_of_id')[0].value == 'Passport') {
        if (doc.id_number.length < 9){
            msgprint ("The ID number cannot be less than 9 characters long");
            validated = false;
        }

    }
}

// code ends here.


Basically what I want to achieve is this:

If the user selects 'Passport' as the type of id then the 'id_number' field must be checked for the length (in this case it shouldn't be less than 9 characters).

I doubt that my syntax is correct, I will greatly appreciate help or suggestion.


Kind regards,
Kat



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Thanks Nabin.

On Tuesday, December 24, 2013 7:10:33 AM UTC+2, Nabin Hait wrote:
To access the value of a form field, don't use getElementByName, instead use doc.type_of_id

On 20-Dec-2013, at 8:23 PM, Kat wrote:

Hello everyone,

I have been trying to find the value of a given field so that I write a condition. Here a sample of the code:


//code starts here
cur_frm.cscript.custom_validate = function(doc){

    if (doc.getElementsByName('type_of_id')[0].value == 'Passport') {
        if (doc.id_number.length < 9){
            msgprint ("The ID number cannot be less than 9 characters long");
            validated = false;
        }

    }
}

// code ends here.


Basically what I want to achieve is this:

If the user selects 'Passport' as the type of id then the 'id_number' field must be checked for the length (in this case it shouldn't be less than 9 characters).

I doubt that my syntax is correct, I will greatly appreciate help or suggestion.


Kind regards,
Kat



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.