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 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Limit spawned fields

    I have the following JavaScript... I would like to limit the number of fields it spawns to 5, how do i do that ? Thanks in advance:

    PHP Code:
    // When the DOM has loaded, init the form link.
    $(
    function(){
    // Get the add new upload link.
    var jAddNewUpload = $( "#add-file-upload" );
     
    // Hook up the click event.
    jAddNewUpload
    .attr"href""javascript:void( 2 )" )
    .
    click(
    function( 
    objEvent ){
    AddNewUpload();
     
    // Prevent the default action.
    objEvent.preventDefault();
    return( 
    false );
    }
    )
    ;
     
    }
    )
     
     
    // This adds a new file upload to the form.
    function AddNewUpload(){
    // Get a reference to the upload container.
    var jFilesContainer = $( "#files" );
     
    // Get the file upload template.
    var jUploadTemplate = $( "#element-templates div.row" );
     
    // Duplicate the upload template. This will give us a copy
    // of the templated element, not attached to any DOM.
    var jUpload jUploadTemplate.clone();
     
    // At this point, we have an exact copy. This gives us two
    // problems; on one hand, the values are not correct. On
    // the other hand, some browsers cannot dynamically rename
    // form inputs. To get around the FORM input name issue, we
    // have to strip out the inner HTML and dynamically generate
    // it with the new values.
    var strNewHTML jUpload.html();
     
    // Now, we have the HTML as a string. Let's replace the
    // template values with the correct ones. To do this, we need
    // to see how many upload elements we have so far.
    var intNewFileCount = (jFilesContainer.find"div.row" ).length 1);
     
    // Set the proper ID.
    jUpload.attr"id", ("file" intNewFileCount) );
     
    // Replace the values.
    strNewHTML strNewHTML
    .replace(
    new 
    RegExp"::FIELD2::""i" ),
    intNewFileCount
    )
    .
    replace(
    new 
    RegExp"::FIELD3::""i" ),
    (
    "presoFile" intNewFileCount)
    )
    ;
     
    // Now that we have the new HTML, we can replace the
    // HTML of our new upload element.
    jUpload.htmlstrNewHTML );
     
    // At this point, we have a totally intialized file upload
    // node. Let's attach it to the DOM.
    jFilesContainer.appendjUpload );


  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by bigrasmusdk View Post
    I have the following JavaScript
    No, you have not a pure native javascript code, that looks like a framework code. Even a framework is a javascript application, it uses custom methods and functions whom we can not imagine what they suppose to do, unless we know which framework is that. Now, what is that: JQuery? Prototype? Mootools? Another... which one?

    Note: You should have not used frameworks for simple tasks like that.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Kor

    What I really want is:
    I have a form that uploads multiple images, I want the form instead to be able to support upto a max of 5 files. And have the files shown like e.g:
    http://picturedumper.com/pages/index/
    (Where when you add more files they will display underneeth eachother) UPTO a max of 5 files

    However I was told that this JavaScript Snippet would do the job... Do you have any other code JavaScript or not that would do the above job. I am not experienced within client-side-coding

    Thanks in advance and happy new year

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    The problem with javascript is that you need to be experienced with client-side coding in order to create, use, debug codes. You can not simply use a javascript snippet without knowing the language. Things do not work like that in web design/developing. A web designer / developer must know javascript, same as he must know HTML and CSS. These 3 languages are the basis and required.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    problem is I know PHP/xHTML and CSS... but these three cannot help me do something client-side that is dynamic!

    JavaScript / mootools could...

    But of course I can understand the basics when I see the JS code... but I was just asking to tweak the current code to enable a limit... there must be some sort of "count" command like in PHP.. but I cannot figure out how to get that to work in the JS code...

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ok. The problem with those frameworks is that you will never know what is hidden behind their custom functions/methods because they are custom. They are not native javascript methods. You may guess or you may start searching for those custom functions/methods in the core of the framework. Which is an intricate job. You could ask people who create that framework. A javascript coder will never be able to help you if he does not know that framework by heart. And usually only the creators are able to.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New Coder
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey again Kor ...I really appreciate your words...

    Anyways what is used is jQuery

    http://docs.jquery.com/Main_Page

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Ok, I have moved your thread into the Javascript Frameworks Forum, where I think you might get the proper support.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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