Check out the LimeSurvey source code on GitHub!

get zipcode as answer to validate with JS

More
6 years 2 months ago #53736 by KRav
Hi there,
have this function to get a zip code and "transform" it to a state.
The problem is the "INSERTANS".. it's not working to get the answer of the question.. saw this in this forum... what going wrong?
<script type="text/javascript" charset="utf-8">
  jQuery(document).ready(function($) {
 
  function zipToState(zip) {
    var states = ['0 500 state1',
                  '501 1000 state2',
                  '1001 1500 state3',
                  '75502 75502 state4'
                 ];
 
    for(var i=0;i<states.length;i++) {
       var d = states[i].split(' ');
          if (zip>=d[0] && zip<=d[1]) return d[2];
     } 
}
 
var zipcode = '{INSERTANS:54579x4x40}'; // numeric field
alert (zipcode);
var state = zipToState(zipcode);
alert(state);
document.getElementById('answer54579x4x127').value= state; // text field
}); 
</script>


research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in to join the conversation.

More
6 years 2 months ago #53744 by DenisChenu
Hello,

What do you have in alert (zipcode); ?

What did you mean on 'not working' ?

Maybe you can try : zipcode = parseInt(zipcode);

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
6 years 2 months ago - 6 years 2 months ago #53745 by KRav
try to alert the zip code , to see if there is something transmitted...

and addation to that the answer field of the "textt field" is empty..

-> seems that something is wrong :-) This code is in the question, where I try to fill the state in a text field

Is there something special if I try to insert a number from an answer?

What could be the cause that "INSERTANS" seems to be empty.. I something in the SGQA Identifier missing? It's a numeric questin type.


research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.
Last Edit: 6 years 2 months ago by KRav.

Please Log in to join the conversation.

More
6 years 2 months ago #53915 by DenisChenu
roB2009 wrote:

try to alert the zip code , to see if there is something transmitted...

ANd you have somthing or not ?

The question 4 is in a page before the question 127 ?

If not: INSERTANS:54579x4x40 are empty. You have to put question 4 on a group before the question 147.

You can use some javascript evenment to do the job with the same page. api.jquery.com/blur/

But then , you can't use INSERTANS, but use the id of the inout box.

.

If the zipcode is in another page, can you give a link of test ?

:)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
6 years 2 months ago #53924 by KRav

ANd you have somthing or not ?

I have nothing.. I expect a stupid typing error..

Yes this two questions are in two different groups..
If I use the result as token in questiontext the result is showing .. on the INSERTANS is not working right...

Yes question 40! is in a group/page before 127


research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in to join the conversation.

More
6 years 2 months ago #53962 by Mazi
It might be useful to set up a small sample survey and place the link here so we can have a look at the source code.
Otherwise it's hard to help.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
6 years 2 months ago #53971 by KRav
stupid typing error

All I had to do, is to use capital "X" in SGQA Identifier. Very important!!!:-)

SOLVED


research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in to join the conversation.

More
6 years 2 months ago #53972 by Mazi
Believe me, you are not the first one who ran into this issue ;)


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form