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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Form not working in Firefox

    I have this javascript and I can not get it to work in firefox or chrome.
    It works fine in IE, need help with what I am doing wrong...
    Code:
    <script type="text/javascript">
    <!-- Begin
    function createForm(number) {
    data = "";    
    inter = "'";
    if (number < 21 && number > -1) {
    for (i=1; i <= number; i++) {
    if (i < 10) spaces="&nbsp; &nbsp;";
    else spaces="&nbsp;";
    data = data + "Image " + i + " :" + spaces
    + "<input type='file' id='userfile' size='50' name=" + inter
    + "image[]" + inter + "'><br>";
    }
    if (document.layers) {
    document.layers.cust.document.write(data);
    document.layers.cust.document.close();
    }
    else {
    if (document.all) {
    cust.innerHTML = data;
          }
       }
    }
    else {
    window.alert("Please select up to 20 entries.");
       }
    }
    //  End -->
    </script>
    Javascript is triggered with
    Code:
    <form name="counter">
    Number of Uploads <input type=text name=number size="2">
    <input type="button" value="Update" onClick="createForm(counter.number.value);">
    </form>
    <form name="newad" method="post" enctype="multipart/form-data"  action="upload.php" onSubmit="return submitForm(this.Submit)">
    <span id=cust style="position:relative;"></span>
    Any help is greatly appreciated!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    document.layers has not been supported since Netscape 4. Use of the non-standard document.all anywhere in a script is a clear indication that the script was originally written for IE4 although it is still supported in IE7.

    Change your script to:-
    Code:
    <script type="text/javascript">
    
    function createForm(number) {
    data = "";    
    inter = "'";
    if (number < 21 && number > -1) {
    for (i=1; i <= number; i++) {
    if (i < 10) {spaces = "&nbsp; &nbsp;"}
    else {spaces = "&nbsp;"};
    data = data + "Image " + i + " :" + spaces
    + "<input type='file' id='userfile' size='50' name=" + inter
    + "image[]" + inter + "'><br>";
    }
    document.getElementById("cust").innerHTML = data;
    }
    else {
    window.alert("Please select up to 20 entries.");
    }
    }
    
    </script>

    The <!--and //--> hiding tags have not been necessary since IE3. They invariably indicate ancient (as here) code.

    Take my advice, I don't use it anyway.
    Last edited by Philip M; 07-14-2009 at 05:36 PM.

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks man,
    I have never writen javascript, so I am clueless on it.
    You have talent my friend, I appreciate your help.
    The code works perfectly!


  •  

    Posting Permissions

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