ciao a tutti
ho un form che fa un controllo dei campi obbligatori (titolo, file o url) con le seguenti righe di javascript:
// check form
$("#btnIns").click(function(){
var ok = true;
var msg = "";
if ($("#titolo").val()!= "")
{
$("#div_titolo").removeClass("error");
}
else
{
$("#div_titolo").addClass("error");
msg = msg + "Titolo, ";
ok = false;
}
// URL o FILE
// messo URL
if ($("#url").val() != "")
{
var re = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
if (re.test($("#url").val()))
{
// verifico se già presente
$.get("ajax/checkUrl.php", { url: $("#url").val() },
function(risposta) {
alert(risposta);
if (risposta!=0)
{
$("#div_url").addClass("error");
msg_url = msg + "URL gia' presente, ";
$("#msg").html("Attenzione: "+msg_url+".");
ok = false;
}
else
{
$("#div_url").removeClass("error");
}
});
}
else
{
$("#div_url").addClass("error");
msg = msg + "URL, ";
ok = false;
}
}
if ($("#fileupload_ok").val()==0 && $("#url").val()=="")
{
msg = msg + "URL o File, ";
ok = false;
}
if (ok)
{
$("#msg").html();
$("#msg").hide();
$("#frm").submit();
}
else
{
$("#div_btn").addClass("error");
$("#msg").html("Verifica i campi obbligatori: "+msg.substr(0,msg.length-2)+". Grazie!");
$("#msg").show();
}
return false;
});
oggi ho aggiunto al form un checkbox così-->
<input type="checkbox" name="cb">
e ho bisogno di renderlo obbligatorio. Ho fatto alcuni esperimenti di aggiunta di righe nel javascript ma non è servito a nulla... ad esempio avevo aggiunto-->
if ($("#cb").val()!= "")
{
$("#div_cb").removeClass("error");
}
else
{
$("#div_cb").addClass("error");
msg = msg + "CB, ";
ok = false;
}
chi mi dà un aiutino??