Welcome, Guest
Username: Password: Remember me

TOPIC: get zipcode as answer to validate with JS

get zipcode as answer to validate with JS 3 years 9 months ago #53736

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
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.
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53744

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6334
  • Thank you received: 818
  • Karma: 243
Hello,

What do you have in alert (zipcode); ?

What did you mean on 'not working' ?

Maybe you can try : zipcode = parseInt(zipcode);
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53745

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
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: 3 years 9 months ago by ResearchOnBlogs.
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53915

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6334
  • Thank you received: 818
  • Karma: 243
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 ?

:)
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53924

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
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.
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53962

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53971

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
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.
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 3 years 9 months ago #53972

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.172 seconds
Donation Image