Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:31:52+00:00 2026-06-11T15:31:52+00:00

please don’t judge my JS skills, I’m complete beginner in it. =)) So I

  • 0

please don’t judge my JS skills, I’m complete beginner in it. =))

So I have a function that register user, But I want to make “create_sample_user” button to fill text fields with some data. This way people can quickly check the website, without typing names, email and so on…

enter image description here

But the problem is: Register button works fine when I type username and all other fields by my self. But Doesn’t work(I assume it just doesn’t ‘see’ the values of the text fields) when I fill them with “create_sample_user” button.

function create_sample_user() {
    var button = $("#create-sample-user");
    button.click(function() {
        var ranNum = 1 + Math.floor(Math.random() * 100);
        var uname = 'Sample_'+ranNum;
        $("#id_username").val(uname);
        $("#id_email").val(uname+'@'+uname+'.com');
        $("#id_password").val(uname);
        $("#id_password2").val(uname);
    });
}

function register_user() {
    $("#register-user").click(function() {
        $.ajax({
            url: "/registration/register_user/",
            type: "POST",
            dataType: "text",
            data: {
                username : $("#id_username").val(),
                email : $("#id_email").val(),
                password : $("#id_password").val(),
                password2 : $("#id_password2").val(),
            },
            success: function(data) {
                parsed_data = $.parseJSON(data);
                if (data) {
                    alert("User was created");
                    window.location = parsed_data.link;
                }
                else {
                    alert("Error");
                }

            }
        });
    });
}

THE ANSWER:

whole thing didn’t work because of one character in this line of code:

`var uname = 'Sample_'+ranNum;` 

For some reason _ character was the problem, and AJAX didn’t want take it.
in other words:

var uname = 'Sample'+ranNum; 

This line would do the trick :=)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:31:53+00:00Added an answer on June 11, 2026 at 3:31 pm

    Okay, replace your create_sample_user() method with this:

    $(document).ready(function() {
        var button = $("#create-sample-user");
        button.click(function() {
            var ranNum = 1 + Math.floor(Math.random() * 100);
            var uname = 'Sample_'+ranNum;
            $("#id_username").val(uname);
            $("#id_email").val(uname+'@'+uname+'.com');
            $("#id_password").val(uname);
            $("#id_password2").val(uname);
        });
    }​);​
    

    Also, try removing the function register_user() function wrapper.

    This should do it. It should pop up the success alert box as well (I changed your AJAX URL to use the AJAX echo for jsFiddle):
    http://jsfiddle.net/MQ6Cq/4/

    UPDATES (since you posted your code – I will update this with bugs as I find them):

    • You have two $(document).ready() calls now – delete the first one (THIS WAS EDITED)
    • You have have to remove the lines function register_user() { and the closing brace from around the register user click handler

    I made a tiny update to my earlier fiddle, just in case it helps with testing, and changed the request type to “GET”. Open your browser’s console (F12), right-click and turn on logging for XMLHttpRequests. Then run it and you will see that the AJAX is successfully transmitting the data. I don’t know what is wrong with your other stuff but I don’t have a server that I can test it on and I’m not getting enough feedback to know what’s going on after you try each suggestion (or even if you’re trying them). I just hope this helps you solve your problem.

    Good Luck! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flash element (I know, but please don't) with a settings.xml file.
Please don't judge me, i'm extremely new on android developing... I wanna make an
I have a bunch of php arrays that look like this (please don't ask
Please don't laugh at me but I believe that I just did something extremely
Please don't answer the obvious, but what are the limit signs that tell us
I state I'm a beginner so please don't miss any step! I used that
Please don't confuse with the title as it was already asked by someone but
Please don't confuse my question with determining the key press. I don't want the
I have mutipule web projects (please don't ask me why with multipule namespaces within
I did a search before asking so please don't tell me to do that.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.