The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: get zipcode as answer to validate with JS

get zipcode as answer to validate with JS 2 years 5 months ago #53736

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • 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 e-mail 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 2 years 5 months ago #53744

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 4409
  • Thank you received: 455
  • Karma: 166
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 2 years 5 months ago #53745

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • 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 e-mail address is being protected from spambots. You need JavaScript enabled to view it
Last Edit: 2 years 5 months ago by ResearchOnBlogs.
The administrator has disabled public write access.

Re:get zipcode as answer to validate with JS 2 years 5 months ago #53915

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 4409
  • Thank you received: 455
  • Karma: 166
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 2 years 5 months ago #53924

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • 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 e-mail 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 2 years 5 months ago #53962

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5116
  • Thank you received: 261
  • Karma: 240
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 2 years 5 months ago #53971

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • 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 e-mail 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 2 years 5 months ago #53972

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5116
  • Thank you received: 261
  • Karma: 240
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.
  • Page:
  • 1
Moderators: DenisChenu, ITEd
Time to create page: 0.267 seconds
Donation Image