/    Sign up×
Community /Pin to ProfileBookmark

Form Validation Error

After following a tutorial, my client side form validation didnt work. As in nothing. It’s like I never wrote any validation code. :S I don’t know what I did wrong…

Here:

[code=php]
<script language=”JavaScript” type=”text/javascript”>
function checkForm()
{
var cby, cproduct, cprice, cdesc, cname, ccontact;
with(window.document.post)
{
cby = by;
cproduct = product;
cprice = price;
cdesc = desc;
cname = name;
ccontact = contact;
}

if(trim(cby.value) == ”)
{
alert(‘Indicate whether you are Buying or Selling’);
cby.focus();
return false;
}
else if(trim(cproduct.value) == ”)
{
alert(‘Please Enter the Product Name’);
cproduct.focus();
return false;
}
else if(trim(cprice.value) == ”)
{
alert(‘Please indicate the Price of the product’);
cprice.focus();
return false;
}
else if(trim(cdesc.value) == ”)
{
alert(‘Please enter a short description about the product’);
cdesc.focus();
return false;
}
else if(trim(cname.value) == ”)
{
alert(‘Please enter the name of the person to be contacted’);
cname.focus();
return false;
}
else if(trim(ccontact.value) == ”)
{
alert(‘Please enter the contact details, such as: cell number, email add, etc.’);
ccontact.focus();
return false;
}
}

function trim(str)
{
return str.replace(/^s+|s+$/g,”);
}
</script>

<form action=”post.php” method=”post” name=”post”>
<table cellpadding=”10″ cellspacing=”0″ border=”0″>
<tr valign=”top”>
<td width=”150″ align=”left”>
Are you Buying or Selling?
</td>
<td align=”left”>
<input type=”radio” name=”by” value=”buying” />Buying <input type=”radio” name=”by” value=”selling” />Selling
</td>
</tr>
<tr>
<td align=”left”>
Product Name:
</td>
<td align=”left”>
<input type=”text” name=”product” size=”50″ maxlength=”99″ />
</td>
</tr>
<tr>
<td align=”left”>
Price:
</td>
<td align=”left”>
<input type=”text” name=”price” size=”10″ maxlength=”11″ /> (In Philippines Pesos)
</td>
</tr>
<tr valign=”top”>
<td align=”left”>
Short Description:
</td>
<td align=”left”>
<textarea class=”input” name=”desc” rows=”3″ cols=”40″></textarea>
</td>
</tr>
<tr>
<td align=”left”>
Contact Person:
</td>
<td align=”left”>
<input type=”text” name=”name” size=”50″ maxlength=”99″ />
</td>
</tr>
<tr valign=”top”>
<td align=”left”>
Contact Details:
</td>
<td align=”left”>
<input type=”text” name=”contact” size=”50″ maxlength=”99″ /><br />(e.g. cell number, email add, etc.)<br />
</td>
</tr>
<tr>
<td align=”left”>
</td>
<td align=”left”>
<input class=”formbtn” type=”submit” value=”SUBMIT AD” name=”sub” onclick=”return checkform();” />
</td>
</tr>
</table>
</form>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 10.2007 — onclick="return check[COLOR="Red"]F[/COLOR]orm();"
and the first if statement is to check 2 radio controls if(!cby[0].checked &amp;&amp; !cby[1].checked)
{
alert('Indicate whether you are Buying or Selling');
return false;
}
Copy linkTweet thisAlerts:
@m_munozauthorNov 11.2007 — The tutorial never mentioned anything about radios, no wonder.

Thanks, it worked!
×

Success!

Help @m_munoz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...