please don't judge my JS skills, this is where I start. =))
So, I have a function that registers the user, but I want to make the "create_sample_user" button to fill in the text fields with some data. This way, people can quickly check the website without entering names, email, etc.

But the problem is that the Register button works fine when I type in the username and all other fields on my own. But it doesn’t work (I assume that it just doesn’t see the value of the text fields) when I fill them with the 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"); } } }); }); }
ANSWER:
the whole thing does not work due to a single character in this line of code:
`var uname = 'Sample_'+ranNum;`
For some reason, the _ symbol was a problem, and AJAX did not want to take it. in other words:
var uname = 'Sample'+ranNum;
This line will do the trick: =)
Vor source share