Random code

  • Profile Image
    guest_23320262919046
    Asked on November 28, 2012 at 12:37 AM
    I need a form that creates random code or codes. How this is possible? Unique ID is not what I'm looking for
  • Profile Image
    idarktech
    Answered on November 28, 2012 at 01:37 AM

    Hi,

    That's possible using your form source code and apply custom script to create such function. An example can be found here. http://idarktech.com/test/random_code_genrate_on_load.html (refreshing the page would generate random 16 alpha-numeric codes.)

    I used this script.

    <script language="javascript" type="text/javascript">

    window.onload = function() {

    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";

    var string_length = 16;

    var randomstring = '';

    for (var i=0; i<string_length; i++) {

    var rnum = Math.floor(Math.random() * chars.length);

    randomstring += chars.substring(rnum,rnum+1);

    }

    document.getElementById('input_1').value = randomstring;

    }

    </script>

     

     

    Variables to set:

    chars - The random string will be created from these characters.

    string_length - The length of the random string.

    input_1 - You should replace this ID to the textbox ID where you'd like to place the random codes.

    Hope this helps. Thanks!

  • Profile Image
    guest_23287996101055
    Answered on November 29, 2012 at 11:34 AM

    This helps a lot! Thanks this awesome.

     

    How this works with rules?

    Let's say I wanna user to select how many random number he want's from 1-10.

    Can I use hidden fields and create rules around them.

    How would javascript look then?

     

  • Profile Image
    abajan
    Answered on November 29, 2012 at 01:33 PM

    @guest_23287996101055

    Please clone this form, embed its full source code into a web page of your choice and place this code at the bottom of the page, right before the closing body tag.

    Here's a demo page containing the form you would have cloned. Go ahead and run some test submissions, chosing a different amount of random numbers each time. After each submission, have a look at the autoresponse in your inbox.

    Please let us know if that's the sort of functionality you were seeking.

    Thanks.

  • Profile Image
    abajan
    Answered on November 29, 2012 at 01:38 PM

    Ha ha... I just realized that the numbers you want generated are in the format my colleague provided. That shouldn't be a problem. Let me do some tinkering with my code and update the demo.

    I'll be back.

  • Profile Image
    abajan
    Answered on November 29, 2012 at 01:59 PM

    @guest_23287996101055

    I've updated the demo to generate 16 character alphanumeric strings. Please test it and let us know what you think.

    Cheers

  • Profile Image
    abajan
    Answered on November 29, 2012 at 02:01 PM

    Oops! I forgot to provide the updated script.

  • Profile Image
    abajan
    Answered on November 29, 2012 at 02:12 PM

    Incidentally, since the IDs of the random number inputs in the demo are sequential (input_1, input_2, input_3 and so on) an extra for loop could have been used to shorten the script, like this.

  • Profile Image
    guest_23287996101055
    Answered on November 29, 2012 at 07:59 PM

    This is amazing! Thank you so much!

     

    One more question:

    Is there any way that I can integrate this randrom number with paypal product quantity?

  • Profile Image
    idarktech
    Answered on November 29, 2012 at 09:32 PM

    @guest_23287996101055

    We'll get in touch with you sooner. Hopefully Master Wayne (a.k.a abajan) will be able to provide what you need as I am sure he understands the code very well.

    But first, we'd like to ask you the form URL or at least reply here using your JotForm Username so we can check the form where you'd like to apply such function and so we can assist you better.

    Thank you!

  • Profile Image
    guest_23287996101055
    Answered on November 30, 2012 at 11:57 AM

    http://form.jotform.ca/form/23344755588263.

    One options is that I create own form for each quantity number but is it possible to collect all the form information from many forms on same google speadsheet document(in my case)?

     

     

  • Profile Image
    Welvin
    Answered on November 30, 2012 at 01:09 PM

    @guest_23287996101055

    One options is that I create own form for each quantity number but is it possible to collect all the form information from many forms on same google speadsheet document(in my case)?

    -Unfortunately, this isn't possible with us.

    Check this guides from Microsoft, this needs you to download your submissions first;

    http://office.microsoft.com/en-gb/excel-help/consolidate-data-from-multiple-worksheets-in-a-single-worksheet-HP010342300.aspx

    http://office.microsoft.com/en-us/excel-help/consolidate-data-in-multiple-worksheets-HP010095249.aspx

    Thanks

  • Profile Image
    guest_23287996101055
    Answered on November 30, 2012 at 02:09 PM

    Yeah I was thinking it might not work.

    I'm still waiting abajan to answer this:

    Is there any way that I can integrate this randrom number with paypal product quantity?

  • Profile Image
    NeilVicente
    Answered on November 30, 2012 at 04:41 PM

    Is there any way that I can integrate this randrom number with paypal product quantity?

    There should be, although I don't understand why anyone would want to buy something at a random quantity. But of course, that's just a personal opinion :)

    Indeed, it would be better to wait for Wayne (abajan) to respond to your questions.

    Regards

  • Profile Image
    abajan
    Answered on November 30, 2012 at 06:41 PM

    @guest_23287996101055

    I had a look at your form but before working on a solution, I want to be sure I understand what is required. On the form, you have stated a desire to have a dropdown quantity menu for each subscription. That can currently be done as explained here but only with products, not subscriptions. What I'm not clear on is how the "random number" functionality is to work. It's stated on the form that the current random number selector is to be replaced with PayPal payment tools. By "payment tools", I presume you mean the form's current payment field that presently contains three subscription elements which will eventually be increased to ten. Do you want a random number of subscriptions to be shown to each user? For instance, there would be 10 subscription elements in all but one user may see

    New Subscripttion 1
    New Subscripttion 2
    New Subscripttion 3

    another user may see

    New Subscripttion 1
    New Subscripttion 2
    New Subscripttion 3
    New Subscripttion 4
    New Subscripttion 5

    and a third user just

    New Subscripttion 1

    Please elaborate. If screenshots would help to clarify what is required, by all means, please use them.

    We look forward to your response.

    Thanks.