Monday, April 12, 2010

Validasi Form Input

<form action="index.php?menu=action" method="post" enctype="multipart/form-data"
name="form1" onsubmit="return validate_form(this)";>
Data: <input type=text name=data1>
Type: <label><input type="radio" name="tipe" value="1">tipe1</label>
<label><input type="radio" name="tipe" value="2">tipe2</label>
<input type="submit" value="submit" name="update">
validation script will be:
function validate_required(field,alerttxt) {
with (field)
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}

function validate_install(thisform) {
with (thisform)
if (!document.form1.tipe[0].checked && !document.form1.tipe[1].checked)
{alert("Choose tipe1 or tipe2!");
return false;}
if (validate_required(data1,"Data must be filled out!")==false)
{data1.focus();return false}
dapat pencerahan dari sini

No comments: