Jump to content

nogray

Members
  • Posts

    930
  • Joined

  • Last visited

Posts posted by nogray

  1. Your index will always starts at -1 because you defined it as var index = -1; in the begining than your function. Instead, you would need to define the index as a global variable

    e.g

    var index = -1;
    setInterval((function() { 
    .... // do not use var index anywhere inside this funciton.
    

  2. You would add an array to hold the error messages and in the end alert that array

    e.g.

    function validateForm(){
    var err_arr = [];
    ...if (x=="")  {
    document.getElementById("li_25").className = "error";
    err_arr.push(' - field name');
    }
    ...
    if (err_arr.length){
    alert('Please complete the following:\n'+err_arr.join('\n'));
    return false;
    }
    return true;
    }
    

  3. You can add a variable on top of your function to hold the valid status and check all the fields. If one is invalid, set the variable to false. In the end of the function, return that variable.

    e.g.

    function validateForm(){
    var is_valid = true;
    ...
    if (x=="")  {
        document.getElementById("li_25").className = "error";
        is_valid = false;
    }
    ...
    return is_valid;
    }
    

  4. The range of dates is approximately 285,616 years from either side of midnight, January 1, 1970. Negative numbers indicate dates prior to 1970.

    If the age is before 1970, you would need to split it and calculate the time before 1970 and add it to the time after 1970.

     

    Also, a date picker is not a good tool for birthdates, I don't want to click back 100 times to get back to my birthdate.

  5. Now I see your html, you have a few issues. You can't have a div as a table element (outside the <td>), this will break your code. You can try to add the id into the tr, but I don't think you can write the tr html directly either. You would need to loop through the table cells inside that tr and update their content.

     

    Sam

  6. You actually need to edit your PHP file on the server to handle the files array. It seems your PHP script is only looking for one input file called data. If you want to do it with JavaScript, the form will have one file input. Add an onsubmit event to the form that create a new iframe, change the form target to the new iframe. After the form is submitted, you would reset it.

     

    You can remove the iframe after you get your results.

  7. When you try to upload multible files, you need to use a array as the name for the input field

    <input type="file" name="my_file[]" />
    

    In your php, you $_FILES['my_file'] should be an array of files, so instead on uploading it once, you would loop through it using a foreach statment

    foreach ($_FILES['my_file']  as $file){
        // upload $file
    }
    

     

    In some servers, using a array name for the input field doesn't work. You get a "string" value "Array" instead of arrays. In that cause, you can use a standard name (e.g. my_file_## where ## is a unique number) and do a foreach loop for the $_FILES and upload all that matches that name, or loop through the $_FILES and upload everything.

     

    Sam

  8. You would first create a new element (e.g. new div) using document.createElement. Append the text in the new element and insert it where you need. You can use the insertBefore method

    e.g.

    var dv = document.createElement('div');
    dv.innerHTML = 'my text';
    var aftr = document.getElement.....;
    aftr.parentNode.insertBefore(dv, aftr.nextSibling);
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.