Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-31-2008, 11:46 AM   PM User | #1
bigrasmusdk
New Coder

 
Join Date: Oct 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
bigrasmusdk is an unknown quantity at this point
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 );

bigrasmusdk is offline   Reply With Quote
Old 01-02-2009, 06:49 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 01-02-2009, 06:08 PM   PM User | #3
bigrasmusdk
New Coder

 
Join Date: Oct 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
bigrasmusdk is an unknown quantity at this point
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
bigrasmusdk is offline   Reply With Quote
Old 01-03-2009, 08:26 AM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 01-05-2009, 03:28 PM   PM User | #5
bigrasmusdk
New Coder

 
Join Date: Oct 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
bigrasmusdk is an unknown quantity at this point
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...
bigrasmusdk is offline   Reply With Quote
Old 01-05-2009, 05:54 PM   PM User | #6
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 01-08-2009, 11:43 AM   PM User | #7
bigrasmusdk
New Coder

 
Join Date: Oct 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
bigrasmusdk is an unknown quantity at this point
hey again Kor ...I really appreciate your words...

Anyways what is used is jQuery

http://docs.jquery.com/Main_Page
bigrasmusdk is offline   Reply With Quote
Old 01-08-2009, 12:20 PM   PM User | #8
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Ok, I have moved your thread into the Javascript Frameworks Forum, where I think you might get the proper support.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:54 PM.


Advertisement
Log in to turn off these ads.