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 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2009
    Location
    New Zealand
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question need help displaying content from array into textarea

    prob solvd
    Last edited by namu; 03-20-2009 at 07:18 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    I do not undersatnd why your code is so complicated. I suggest you rework it like this:-


    Code:
    <script type = "text/javascript">
    
    var results = new Array();
    results[0] = document.registerform.studentname.value;
    results[1] = document.registerform.studentphone.value;
    results[2] = document.registerform.mfgender.value;
    var string = results.join("\n")
    document.getElementById("txtarea").value = string;
    
    </script>
    
    OR
    
    string = "Welcome " + results[0];
    string = string + "\nName: " + results[0];
    string = string + "\nPhone: " + results[1];
    string = string + "\nGender: " + results[2];
    document.getElementById("txtarea").value = string;
    
    </script>
    Validation such as
    if (document.registerform.studentname.value == "") {
    is barely worthy of the name as a single character or even a space or a ? will return true.
    Likewise
    if (document.registerform.studentphone.value == "")
    does not require numbers.

    To be candid, I think this assignment wants a total make-over.


    “If you only do what you know you can do - then you never do very much.” - Tom Krause
    Last edited by Philip M; 03-19-2009 at 10:13 AM.

  • Users who have thanked Philip M for this post:

    namu (03-19-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Location
    New Zealand
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    prob solvd
    Last edited by namu; 03-20-2009 at 07:19 AM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    "I do not need the insert and show functions anymore?" Well, no.


    You must place the code within a function, and call the function in your submit. But before that you need to call another function to validate the input as I mentioned.

    To be candid I think you are trying to walk before you can crawl. As I say, I suggest that you start over, using the code I have given you.


    Code:
    function yourName () {
    var results = new Array();
    results[0] = document.registerform.studentname.value;
    results[1] = document.registerform.studentphone.value;
    results[2] = document.registerform.mfgender.value;
    var string = results.join("\n")
    document.getElementById("txtarea").value = string;
    }
    
    </script>
    
    <input type="submit" value="Submit" name="submitform" " onclick="yourName()"/>
    Last edited by Philip M; 03-19-2009 at 11:57 AM.

  • #5
    New Coder
    Join Date
    Mar 2009
    Location
    New Zealand
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    solvd
    Last edited by namu; 03-20-2009 at 07:21 AM.


  •  

    Posting Permissions

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