0

I am using Buddy.com's API to build a mobile app with a web Interface for Administrators and User Creation. I am still in the initial stages of this project.

The first page I am trying to build is the User Registration page for the website. This page will have a form asking the users for a username, password, email and some other fields.

I am using the javascript form the page http://buddy.com/developers/#UserAccount_Profile_Create

The function is: function createUserWithName(); And it has some inputs. The function looks like this:

function fixedEncodeURIComponent (str) {  
    return encodeURIComponent(str).replace(/[!'()*]/g, escape);  
}
function createUserWithName(aName, anEmail) 
{
    var finalURLStr = "https://webservice.buddyplatform.com/Service/v1/BuddyService.ashx";

    finalURLStr += "?UserAccount_Profile_Create";    // API Call
    finalURLStr += "&BuddyApplicationName=" + fixedEncodeURIComponent("<#Buddy App Name#>");
    finalURLStr += "&BuddyApplicationPassword=" + fixedEncodeURIComponent("<#Buddy App Password#>");
    finalURLStr += "&NewUserName=" + fixedEncodeURIComponent(aName);                    // The user name
    finalURLStr += "&UserSuppliedPassword=" + fixedEncodeURIComponent("<#password#>");  // User password
    finalURLStr += "&NewUserGender=" + "male";                                          // "male" or "female"
    finalURLStr += "&UserAge=" + 29;                                                    // user age (int)
    finalURLStr += "&NewUserEmail=" + fixedEncodeURIComponent(anEmail);                 // user email
    finalURLStr += "&StatusID=" + -1;                                                   // see status table (1-7 or -1)
    finalURLStr += "&FuzzLocationEnabled=" + 1;                                         // true / false: location isn't/is reported accurately
    finalURLStr += "&CelebModeEnabled=" + 0;                                            // true if user is hidden from non-friends
    finalURLStr += "&ApplicationTag=";                                                  // app-related info
    finalURLStr += "&RESERVED=";                                                       // leave empty

    $.ajax({ url: finalURLStr })
        .done( function(data) {
            // Result is a simple string
            alert("Result: " + data);
        })
        .fail(function() {
            alert("Error while contacting Buddy!");
       });
}

I have created a form which asks for the user to input this information.

How can I pass the field data from my form to this function?

This is the code for my form:

<form id="register">

<table width="200" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><label for="username">Username*:</label>
        <input type="text" id="username" name="username" />
    </td>
  </tr>
  <tr>
    <td><label for="password">Password*:</label>
        <input type="text" id="password" name="password" />
    </td>
  </tr>
  <tr>
    <td><label for="email">Email*:</label>
        <input type="text" id="email" name="email" />
    </td>
  </tr>
  <tr>
    <td><label for="gender">Gender*:</label>
        <select id="gender">
            <option value="null">Please Choose One...</option>
            <option value="Male">Male</option>
            <option value="Female">Female</option>
        </select>
    </td>
  </tr>
</table>
<input class="button" name="submit" type="button" value="submit" onclick="createUserWithName(username.value)" />
</form>

Im sure that once someone shows me how to send the username and email to the javascript function I will be able to figure out the rest.

Thank you

3
  • Is the javascript included in the html page? Commented Aug 26, 2013 at 10:00
  • Yes, i have put it as part of the HTML page. Commented Aug 26, 2013 at 11:39
  • Check my answer. That should work. Commented Aug 26, 2013 at 11:54

4 Answers 4

2

first create a function in which you collect all the form data

function getFormData(){ 
var name=document.getElementById('username').value;
var email=document.getElementById('email').value;
/* some other fields */
/* now call ur function by passing the above values */
createUserWithName(name, email);
}

In your form call getFormData() method

<input class="button" name="submit" type="submit" value="submit" onclick="getFormData()" />
Sign up to request clarification or add additional context in comments.

5 Comments

I tried this, I am getting a TypeError error, at the line: var name=document.getElementById('username').value();
sorry, remove () for value function.. just document.getElementById("username").value;
Is there is a better(secure) way to input password?
I observed that you have written type="text" for password which shows the characters you enter.. change it to "password"
i already did that. I meant, while passing the password value in the javascript function. Can this be done in a more secure way?
2

You can just use:

document.getElementById('username').value

in your javascript function. Alert the value to check if you are getting it.

Comments

0

there are many ways, but you can use jquery stuff

username = $("username").val();

Comments

0
var username = $("#username").val();
var email= $("#email").val();
createUserWithName(username , email);

2 Comments

OOPS! Sorry, i completely forgot to include the jquery library! So this works now :)
It did, However Girish's answer was more holistic and detailed, which is why i chose that one. Thanks for the response :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.