Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Stop input

  1. #1

    Stop input

    Ciao a tutti. Avrei un piccolo problema. Ho reperito sulla rete uno script che permette di uploadare più file: schiacciando il link "Aggiungi file" si aggiunge un campo. Peccato però che non ci sia un limite. Ed è qui che vi chiedo una mano: come faccio a dare un limite...diciamo di quattro campi?
    Di seguito il sito: http://urbantrash.altervista.org/gallery e il codice javascript: http://urbantrash.altervista.org/gallery/esterno.js
    Grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Nel file javascript che hai linkato, in alto, la prima riga dice

    codice:
    var max = 0;				// maximum # of attachments allowed
    Suppongo che 0 sia il valore di default per dire "quanti ne vuoi", prova a modificare quel valore in 4 o quanti ne vuoi tu e vedere se cambia qualcosa. A dire il vero non ho letto il resto dello script per mancanza di tempo.
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Avevo già provato ma non funzionava...non so perchè...

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Allora ho dato un'occhiata al codice... vedi se così va meglio:
    codice:
    function addUpload(fileFieldName){
      if (max == 0 || currentUploads <= max) {
    	nameFile=fileFieldName;
    	currentUploads++;
    	if (currentUploads>0)
    		document.getElementById('addupload').childNodes[0].data='Aggiungi file';
    	// First, clone the hidden attachment section
    	var newFields = document.getElementById('attachment').cloneNode(true);
    	newFields.id = '';
    	// Make the new attachments section visible
    	newFields.style.display = 'block'; 
    	// loop through tags in the new Attachment section
    	// and set ID and NAME properties
    	//
    	// NOTE:	the control names for the Description Input
    	//			field and the file input field are created
    	//			by appending the currentUploads variable
    	//			value to the nameFile and nameDesc values
    	//			respectively
    	//
    	//			In terms of Xaraya, this means you'll need to name your
    	//			DD properties will need names like the following:
    	//				"AttachmentDesc1"
    	//				"AttachmentFile1"
    	//				"AttachmentDesc2"
    	//				"AttachmentFile2"
    	//				"AttachmentDesc3"
    	//				"AttachmentFile3"
    	//				et cetera...
    	var newField = newFields.childNodes;
    	for (var i=0;i<newField.length;i++){
    		if (newField[i].name==nameFile){
    			newField[i].id=nameFile+currentUploads;
    			newField[i].name=nameFile+'[]';
    			//newField[i].name=nameFile+currentUploads;
    		}
    	}
    	// Insert our new Attachment section into the Attachments Div
    	// on the form...
    	var insertHere = document.getElementById('attachmentmarker');
    	insertHere.parentNode.insertBefore(newFields,insertHere);
      } // chiudo l'if aperto all'inizio
    }
    a questo punto credo che il parametro max sia utilizzabile sensatamente
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  5. #5
    Purtroppo anche così non funziona...
    Tra l'altro non funziona il tasto rimuovi così...

  6. #6
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    e ti credo: invece di sostituire una funzione (quella postata) hai sostituito l'intero file...
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  7. #7
    Ma scusa...non deve essere così?

    codice:
    var max = 4;				// maximum # of attachments allowed
    var currentUploads = 0;		// current # of attachment sections on the web page
    var nameDesc = '';			// Name property for the Description Input field
    var nameFile = '';			// Name property for the File Input field
    var scrollPosVert = 0;		// stores the current scroll position on the form
    
    // for some reason when a div is taken out, the form
    // will scroll to the top on both Firefox and IE
    
    // SCROLL FUNCTIONS
    function saveScrollPos(offset){
    	scrollPosVert=(document.all)?document.body.scrollTop:window.pageYOffset-offset;
    }
    
    function setScrollPos(){
    	window.scrollTo(0, scrollPosVert);
    	setTimeout('window.scrollTo(0, scrollPosVert)',1);
    }
    
    
    // This function adds a new attachment section to the form
    // It is called when the user clicks the "Attach a file" button...
    // It takes three arguments:
    //      maxUploads			- the maximum number of attachments allowed
    //		descFieldName		- the field name for the Description Input field
    //		fileFieldName		- the field name for the File Input field
    function addUpload(fileFieldName){
      if (max == 0 || currentUploads <= max) {
    	nameFile=fileFieldName;
    	currentUploads++;
    	if (currentUploads>0)
    		document.getElementById('addupload').childNodes[0].data='Aggiungi file';
    	// First, clone the hidden attachment section
    	var newFields = document.getElementById('attachment').cloneNode(true);
    	newFields.id = '';
    	// Make the new attachments section visible
    	newFields.style.display = 'block'; 
    	// loop through tags in the new Attachment section
    	// and set ID and NAME properties
    	//
    	// NOTE:	the control names for the Description Input
    	//			field and the file input field are created
    	//			by appending the currentUploads variable
    	//			value to the nameFile and nameDesc values
    	//			respectively
    	//
    	//			In terms of Xaraya, this means you'll need to name your
    	//			DD properties will need names like the following:
    	//				"AttachmentDesc1"
    	//				"AttachmentFile1"
    	//				"AttachmentDesc2"
    	//				"AttachmentFile2"
    	//				"AttachmentDesc3"
    	//				"AttachmentFile3"
    	//				et cetera...
    	var newField = newFields.childNodes;
    	for (var i=0;i<newField.length;i++){
    		if (newField[i].name==nameFile){
    			newField[i].id=nameFile+currentUploads;
    			newField[i].name=nameFile+'[]';
    			//newField[i].name=nameFile+currentUploads;
    		}
    	}
    	// Insert our new Attachment section into the Attachments Div
    	// on the form...
    	var insertHere = document.getElementById('attachmentmarker');
    	insertHere.parentNode.insertBefore(newFields,insertHere);
      } // chiudo l'if aperto all'inizio
    }

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    no, c'erano delle altre funzioni in quel file (per esempio quella che rimuoveva i campi upload...) che non andavano toccate.
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  9. #9

  10. #10
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    ottimo, vedo che va. (e in firefox la pagina è tanto più accattivante rispetto a IE6, penso sia per le trasparenze che IE < 7 ignora)
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.