|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Clientside validation
Hi
I have made a simple form: 3 textboxs, a imagebutton and calender. The calender becomes visible when you click on the imagebutton. You select a date and this date comes in textbox1. the 2 other textboxs you can fill in whatever you want. Now i want to validate if the 3 textboxs are filled in. If there is an empty textbox, i want to show a messagebox. I have tried to use validation controls but when you click on the imagebutton the form is postbacked. Also when you select a date from the calender the form is postbacked. I see only one solution and this is to work whit javaScript to validate the 3 textboxs but i can't seem to get the text attribute from a textbox in javaScript. Can onyone help me? If you think of a way to validate this form serverside even better. thanks joekske ![]() |
|
#2
|
|||
|
|||
|
Well, your best option is to validate both ways - client and server side. So, use javascript to pop your message on the user if the fields are not filled in but also validate it server side with php.
Whats your code look like - the jscript you are having problems with?
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#3
|
||||
|
||||
|
I'm curious as to how you're displaying a calender... perhaps you could provide a link, or your code, to reveal a peek at what you're doing.
As for your textboxes, it's the value attribute in javascript... Quick example: Code:
if (document.form.textbox1.value=="whatever") {
alert("Whatever!");
}
Depending on what's going into your text boxes, you might want to consider Regular Expressions to validate the fields. Quick example for validating email address Code:
var r, re;
var email = document.form1.email;
re=/[a-zA-Z].\@.[a-zA-Z]/;
if(r=re.exec(email.value)) {
alert("Valid email");
} else {
alert("Invalid email:\nuser@host.com");
}
I hope some of this helps... i strongly agree with jpenn too, serverside validate as well... keeps invalid data out of your database. |
|
#4
|
|||
|
|||
|
Code
here is the code
ps: if (document.form.textbox1.value=="whatever") { alert("Whatever!"); } doesn't work c u joekske |
|
#5
|
|||
|
|||
|
Try:
Code:
function checkValues()
{
if ( document.getElementById( 'textfield' ).value == '' )
{
alert('Empty!');
}
}
</script>
</head>
<body>
<form name="form" method="post" action="">
<input type="text" name="textfield"><br />
<input type="submit" name="Submit" value="Submit" onclick="checkValues()">
</form>
Just run that as is and see if that is what you are looking for. If it is, use it as a starting point... |
|
#6
|
|||
|
|||
|
when I use javascript to valididate a form, i use something like this
PHP Code:
Basically it just goes though the list, if theres a problem it returns false, and the form is not submitted, other wise it submit the form. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Clientside validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|