Mostrando las entradas con la etiqueta JS. Mostrar todas las entradas
Mostrando las entradas con la etiqueta JS. Mostrar todas las entradas

miércoles, 10 de marzo de 2010

Required field(s) validation v1.10- By NavSurf

Súper recomendado! hace un muy buen paro!

<pre><script language="JavaScript">
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
 // Enter name of mandatory fields
 var fieldRequired = Array("FirstName", "LastName");
 // Enter field description to appear in the dialog box
 var fieldDescription = Array("First Name", "Last Name");
 // dialog message
 var alertMsg = "Please complete the following fields:\n";

 var l_Msg = alertMsg.length;

 for (var i = 0; i < fieldRequired.length; i++){
  var obj = formobj.elements[fieldRequired[i]];
  if (obj){
   switch(obj.type){
   case "select-one":
    if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
     alertMsg += " - " + fieldDescription[i] + "\n";
    }
    break;
   case "select-multiple":
    if (obj.selectedIndex == -1){
     alertMsg += " - " + fieldDescription[i] + "\n";
    }
    break;
   case "text":
   case "textarea":
    if (obj.value == "" || obj.value == null){
     alertMsg += " - " + fieldDescription[i] + "\n";
    }
    break;
   default:
   }
   if (obj.type == undefined){
    var blnchecked = false;
    for (var j = 0; j < obj.length; j++){
     if (obj[j].checked){
      blnchecked = true;
     }
    }
    if (!blnchecked){
     alertMsg += " - " + fieldDescription[i] + "\n";
    }
   }
  }
 }

 if (alertMsg.length == l_Msg){
  return true;
 }else{
  alert(alertMsg);
  return false;
 }
}
// -->
</script>



&lt;!--SAMPLE FORM --------------------------------&gt;

<form name="formcheck" onsubmit="return formCheck(this);">
First Name: <input name="FirstName" size="25" type="text" />
Last Name: <input name="LastName" size="25" type="text" />
<input type="submit" value="Submit Form" />
</form>
</pre>

martes, 9 de diciembre de 2008

Limit file uploads by extension


Nice & easy! A great JS Script... I'm keeping the credits, this ain't mine!


<SCRIPT LANGUAGE="JavaScript">
<!-- Original: ArjoGod, Shauna Merritt -->
<!-- Modified By: Ronnie T. Moore, Editor -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
extArray = new Array(".jpg");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
}
// End -->
</script>


And to make it work, just apply it on the submit input

<input type="submit" onclick="LimitAttach(this.form, this.form.input_file_name.value)" />