1

Newbie in Javascript, i am trying to create a simple form that creates a list of items based on an array which the user fills in. How can i have a list of items created based on the Array x -- Thanks in advance

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title></title>
    <script type="text/javascript">
    function checkwarranty()
    {
      var x = new Array();

      x[0] = document.getElementById('clientname').value;
      x[1] = document.getElementById('select').value;
      x[2] = document.getElementById('expirationdate').value;
      x[3] = document.getElementById('notifyon').value;
    }
    </script>
  </head>
  <body>
    <form>
      <table border="1">
        <tr>
          <td>Client Name:</td>
          <td>
            <input type="text" name="clientname" id="clientname">
          </td>
        </tr>
        <tr>
          <td>Device Type:</td>
          <td>
            <select id="select">
              <option value="Server">Server</option>
              <option value="Server">Firewall</option>
              <option value="Server">Domain</option>
              <option value="Server">Desktop</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>Warranty Expires on:</td>
          <td>
            <input type="date" name="expirationdate" id="expirationdate">
          </td>
        </tr>
        <tr>
          <td>Notify On:</td>
          <td>
            <input type="date" name="notifyon" id="notifyon">
          </td>
        </tr>
      </table><br>
      <input type="button" name="submit" value="submit" onclick="checkwarranty()">
    </form>
  </body>
</html>

1 Answer 1

1

Multidimensional Arrays is what you want. Try this

var list = [];

function checkwarranty()
{
    var x = [];

    x[0] = document.getElementById('clientname').value;
    x[1] = document.getElementById('select').value;
    x[2] = document.getElementById('expirationdate').value;
    x[3] = document.getElementById('notifyon').value;

    list.push(x);
}

For more Information check http://www.w3schools.com/jsref/jsref_obj_array.asp

Sign up to request clarification or add additional context in comments.

4 Comments

Most people use the list = []; syntax these days.
I find var list = new Array(); a lot more readable. Besides, I think you could just push the four values into list without the detour to create an array x.
@momro I thought the question was to create a multi dimensional array. Like a list of list objects :-)
i wanted every time a user click submit a list shows at the bottom of the page with the item information.

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.