54 users online (1 members and 53 guests)  


Page 1 of 2 1 2 Last
  Results 1 to 15 of 22

Related

  1. Checkboxes and arrays    Forum: Javascript Forum
    Replies: 18
  2. Problem with forms    Forum: HTML Forum
    Replies: 1
  3. operations with files and arrays    Forum: PHP Forum
    Replies: 4
  4. Replies: 0
  1. #1
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Problem with arrays and forms

    Someone please help me.

    I have 2 problems:

    1. Im going to make a booking calender. I need to declare an array in Javascript, at the same moment you reaches the page. Every date has an checkbox. If you click the checkbox, a function will be called. This function will add an variable to the array, and the value of the variable has to be the ID of the checkbox you just have checked. You can check as many checkboxes you want, and for each time the function will add an variable to the array. How can I do all this?

    2. There also have to be a Next-button. When you click this, you will reach another page, where there is a form (textfield). The content of this form has to be all the variables in the array, seperated by an comma. How can I send the array from the previous page into the form?

    I hope someone can help me.

  2. #2
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Problem with arrays and forms

    Use the push() method.
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.

  3. #3
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Thanks rangana, that was a good tutorial. But do you know how to return the array into the form in the next page? Do I have to use an external .js file?

  4. #4
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Problem with arrays and forms

    You would rely on cookies for that, or you could append the value via the URL and let JS get the address' string
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.

  5. #5
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Allright, I think the best sollution is the URL-method, but how can I do that...
    Last edited by adamsen; 02-05-2009 at 08:54 AM. Reason: Wrong words

  6. #6
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Problem with arrays and forms

    Pass the array via URL:
    Code:
    location.href='site.com/index.php?array='+arrVar;
    ...then on site.com/index.php, check if for the URL:
    Code:
    if(location.href.indexOf('array=')>1){
    	var arrVal = location.href.split('array=')[1]; // Get the values
    	alert(arrVal); // Let me know what it is. For test
    }
    Hope that makes sense.
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.

  7. #7
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Thanks, great code. I canīt use PHP, my host doesnīt allow it. But I hope you can tell me if it works. I want to display the array in a textarea.

  8. #8
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Problem with arrays and forms

    Just replace this part:
    Code:
    alert(arrVal); // Let me know what it is. For test
    ...with your assigning of value to the textarea:
    Code:
    document.getElementById('id_of_the_textarea').value = arrVal;
    Hope that helps.
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.

  9. #9
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Eeem, it will not work if I type this code (my host doesnīt allow PHP you know):
    HTML Code:
    <script type="text/javascript">	
    arrVal = 4;
    document.getElementById('text').value = arrVal;
    </script><textarea id="text" cols="4 rows="4"></textarea>
    Last edited by adamsen; 02-06-2009 at 10:10 AM.

  10. #10
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Problem with arrays and forms

    Who told you this is PHP? The code is Javascript.

    The problem at your end is that the code is firing even if your markup hasn't been fully loaded yet.

    With that said, you could either choose from these fixed:
    • Let the script run when the page has fully loaded:
      Code:
      window.onload=function() {
      	arrVal = 4;
      	document.getElementById('text').value = arrVal;
      }
    • Place the script after the markup:
      Code:
      <textarea id="text" cols="4 rows="4"></textarea>
      <script type="text/javascript">	
      arrVal = 4;
      document.getElementById('text').value = arrVal;
      </script>


    I prefer the former though.

    Also, you missed on closing your cols attribute.

    Hope that makes sense.
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.

  11. #11
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Okay rangana, Iīm a bit confused. If you could tell me everything once again, I would be grateful.
    I have to html-pages: book.html and send.html
    In the first, form.html I have a button. When I click this, some code will validate the input from
    some forms, and then the array will be saved by an URL. Then the code will redirect me to send.html,
    and then in a textarea there will be the content of the array. What will the code be for this?

  12. #12
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    Okay rangana, Iīm a bit confused. If you could tell me everything once again, I would be grateful.
    I have to html-sites: book.html and send.html
    In the first, form.html I have a button. When I click this, some code will validate the input from
    some forms, and then the array will be saved by an URL. Then the code will redirect me to send.html,
    and then in a textarea there will be the content of the array. What will the code be for this?

  13. #13
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: Problem with arrays and forms

    oops for me too removed
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  14. #14
    adamsen's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    128

    Re: Problem with arrays and forms

    OOPS, I posted it 2 times... sorry, I couldnt find it

  15. #15
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: Problem with arrays and forms

    I did not realize we were on page 2. It looked like you started a new thread and not a response...my fault
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting



Page 1 of 2 1 2 Last

Tags for this Thread