/    Sign up×
Community /Pin to ProfileBookmark

I have an array question?

I am know to Javascript so this is probably a basic question. How do I store user information from a field to an array and call it using a button to print it out later?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERApr 02.2009 — Need more information.

  • 1. What kind of information? Number, string, logic? Any special formatting?

  • 2. What kind of field? Textbox, Textarea, selectbox value, radio button value?


  • Too many unknowns to comment.


    Post what you have up to the point of problems.

    ?
    Copy linkTweet thisAlerts:
    @wb31authorApr 02.2009 — Ok, I am looking to use a text field where the user can enter their name. The kind of information is a string. When the add button is activated an alert box shows their name.

    Here is my code

    <html>

    <head>

    <script>

    function submitForm()

    {

    var myForm = document.registrationForm;

    var user_name = name;
    var name = document.getElementById("enterName");



    var myUserName;


    var name = "";
    var userarray;



    if (myUserName == "")
    {
    var userarray = new Array();
    var myUserName = myForm.user_name.value;
    myName = "<p style=color:red>Please enter your First name.</p>";
    myUserName = name;
    name.innerHTML = myName;
    //alert(myUserName);
    return false;
    }
    else
    {
    var userarray = new Array(1);
    userarray[0] = "";
    var myUserName = myForm.user_name.value;
    myUserName = userarray;
    alert(userarray[0] = "");
    }

    }

    </script>

    </head>

    <scprit>

    <body>

    <form>

    <table bgcolor="silver">
    <thead>
    <tr>
    <th><h1>String Manipulation Assignment<h1></th>
    </tr>

    </thead>
    <tbody>
    <tr>
    <td><h2>Search/Add Students<h2></td>
    </tr>
    <tr>
    <td>Name<input id="user_name" type="text" name='user_name'></td>
    <td><p align="left" id="enterName"></p></td>
    </tr>

    <tr>
    <td>
    <input name="btnAdd" type="submit" value="Add" onclick="submitForm();">
    <input name="btnReset" type="reset" value="Reset" onclick="btnReset();"></td>

    </tr>
    </tbody>
    </table>

    </form>

    <p id="printName"></p>


    </body>

    </script>

    </html>
    Copy linkTweet thisAlerts:
    @JMRKERApr 03.2009 — You have a number of errors that will not allow the script to run. :eek:

    If using FF, check the error console. ?

  • 1. <script> tag needs further definition: <script type="text/javascript">

  • 2. Mis-spelled <script> tags

  • 3. Not correctly nested <script> tags, ie surrounding <body> ???

  • 4. Form name is missing.

  • 5. Add some alert('Messages') at different locations to see values assigned as you debug.


  • Use [ code] [ /code] tags (without spaces) around you scripts to make it easier to read.
    ×

    Success!

    Help @wb31 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...