Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic Javascript help please

    Hi all,

    I've completed the basic outline for my app and have spent a few weeks learning the Javascript basics but I'm still stuck!

    I've made a textfield and a button. I'm trying to store what the user enters in the textfield once the button is clicked and insert into an array which is then shown on a seperate page. This will then be the title for another array but I'm just trying to do the first step for now!

    I appreciate this is very basic but I'm stuck!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    I am not sure that I understand. Is your "textfield" a textbox or a textarea? What do you mean by "inserted" into an array? What do you mean by "a title for another array"? Please give us a concrete example of what you are trying to do.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I'm a total newbie to this. The 'text box' is a text area.

    I thought an array is a container for multiple values? What I am trying to do is create an app in which the user creates list titles and can add information to each list.

    So the display shows a textbox and button. The user enters a title and 'saves' it using the button. Another screen shows the titles in which the user can then add more titles. After this they can add information but for now I'm just trying to do the first step of creating the first set of titles.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    One more time - textbox or textarea? If you don't know the difference then ......

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,983
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Why does it have to go to the second screen? You're just complicating things for yourself there. Maybe the best way to clear up the text box/area/field confusion is just to show us the code you have so far...

  • #6
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol why does it matter if it's a textarea or textbox? the proccess is the same

    //create array on localStorage if there isn't already one
    if (!localStorage.array) {localStorage.array=[];}
    //get the textbox/text area that has an id attribute
    textElement=document.getElementById('text');
    //get the button that has an id attribute
    button=document.getElementById('button');
    //add event listener to button
    button.addEventListener('click',function() {
    //get text in textbox
    text=textElement.value;
    //put text in array
    localStorage.array.push(text);
    location="next_page.html";
    },false);



    //and on the next page:

    for (var i=0; i<localStorage.array.length; i++){
    //print out each item from array
    document.write(localStorage.array[i]+" ");
    }

    //not this only works if your browser supports localStorage, most do


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •