• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

javascript validation..(interview question)

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The flollowing code is a question asked me for an interview.....Anyone can help me how to validate this form professionaly.....using javascript. please help me........

1. Consider the following fragment of HTML.
<SCRIPT LANGUAGE=javascript>
<!--
function checkRequired() {
...
}
//-->
</SCRIPT>
...
<form name=RegForm method=post onsubmit="checkRequired()">
<table>
<tr><td>*Title:</td>
<td><select name=Title>
<option selected>Mr</option>
<option>Mrs</option>
<option>Ms</option>
<option>Miss</option>
</select></td></tr>
<tr><td>First name:</td>
<td><input type=text name=FirstName size=20 maxlength=20 value=''></td></tr>
<tr><td>Last name:</td>
<td><input type=text name=LastName size=20 maxlength=20 value=''></td></tr>
<tr><td>Date of birth:</td>
<td><input type=text name=DOB size=20 maxlength=20 value=''>
<tr><td>Address:</td>
<td><input type=text name=Address size=30 maxlength=128 value=''></td></tr>
<tr><td>Town:</td>
<td><input type=text name=Town size=30 maxlength=40 value=''></td></tr>
<tr><td>County:</td>
<td><input type=text name=County size=30 maxlength=40 value=''></td></tr>
<tr><td>Postcode:</td>
<td><input type=text name=PostCode size=20 maxlength=10 value=''></td></tr>
<tr><td>Email:</td>
<td><input type=text name=Email size=30 maxlength=64 value=''></td></tr>
</table>
</form>
...
Write the checkRequired function to check all information fields inputted by user (all fields are mandatory).The function must check the validity of every parameter (on the basis of rational acceptability) and make a proper
(case-sensitive) formatting for the all form's text fields.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look at my sig, it will get you started.
All I can say is if you can not do this without someone's help, then how are you going to do your job?
This is an easy thing they asked, could do the whole thing in less then 10 minutes.
Eric
[ October 12, 2003: Message edited by: Eric Pascarello ]
[ October 12, 2003: Message edited by: Eric Pascarello ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I would start by adding a submit button.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could help you with a few hints on how to validate a form un-professionaly.
 
Friend
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric, Thomas and Mike,
YOU ARE GREAT PEOPLE !!! I UNDERSTAND...........AND ALSO UNDERSTAND THAT YOU KNOW NOTHING OHTERTHAN MAKING SILLY COMMENTS
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a generic validation script. You can see it in action here. It uses additional form element tags to perform specific validation.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DID YOU EVEN BOTHER TO LOOK AT MY SIGNATURE? I wrote the stupid thing that you need to get a job. You just need to make two simple changes on certain things. If you were capleable of doing those changes then you might deserve the job.
Eric
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following HTML code snippet:
<SCRIPT LANGUAGE=javascript>

<!--
function checkRequired() {


}

//-->

</SCRIPT>

<form name=RegistrationForm method="post"
onsubmit="checkRequired()">

<table>

<tr><td>*Title:</td>

<td><select name="title">

<option selected>Mr</option>

<option>Mrs</option>

<option>Ms</option>

<option>Miss</option>

<option>Dr</option>
<option>Prof</option>
</select></td></tr>

<tr><td>First name:</td>

<td><input type="text" name="firstName" maxlength="20" /></td></tr>

<tr><td>Last name:</td>
size="20"
<td><input type="text" name="lastName" maxlength="20" /></td></tr>

<tr><td>Date of Birth:</td>
size="20"
<td><input type="text" name="dob" maxlength="20"/>

<tr><td>Address:</td>
size="20"
<td><textarea name="address" cols="40"></textarea></tr>

<tr><td>Town:</td>
row="4",
<td><input type="text" name="town" maxlength="40"/></td></tr>

<tr><td>County:</td>
size="30"
<td><input type="text" name="county" maxlength="40"/></td></tr> size="30"

<tr><td>Postcode:</td>

<td><input type="text" name="postcode" size="20" maxlength="10" /></td></tr>

<tr><td>Email:</td>

<td><input type="text" name="email" size="30" maxlength="64"/></td></tr>

</table>

</form>

...

Write the checkRequired function to check all information fields inputted by user (all fields are mandatory). The function must check the validity of every parameter (on the basis of rational acceptability) and make a proper (case-sensitive) formatting for the all form's text fields.
 
Marshal
Posts: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

How does your post differ from the original from 2003?
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic