|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to Control Fields
How may I control a form field that only could accept values from 00 to 99. Just this.
And I have two fields and both must be completed or filled to be proccesed, that mean you can't submit it without to complete both field.. how may I control this. NVM |
|
#2
|
|||
|
|||
|
Re: How to Control Fields
What language? PHP?
There are two times to check the value: 1. Before sending the form 2. After sending the form (when receiving it). Before Use Javascript to test the value: PHP Code:
After You can't rely on Javascript alone. The visitor may have turned it off. Therefore you also have to check the values in your PHP script: PHP Code:
Quote:
Implement a Javascript function both_fields_filled() to return true if both fields are filled, false otherwise. Then use PHP Code:
|
|
#3
|
|||
|
|||
|
I could validate the forms, with this script, I just wanted control that nobody could submit a form with a blank form1.. this is the script..
<script> <!-- function validate() { if (document.form1.valor.value=="") { alert ("Por favor introduzca el Valor de la Jugada") return false } if (document.form1.numero.value=="") { alert ("Por favor introduzca el Número a Jugar") return false } } //--> </script> But I have a problem, it returns the Alert if it is blank, but when I submit the form it process a script an it run in the target='_blank', because I need it so.. but, if one the field of the form is blank it show the message, but doesn't return to the form, it continue, I need it stay in the form until the user complete the form.. |
|
#4
|
||||
|
||||
|
Make sure that your form tag is as follows (as posted by md2perpe):
Code:
<form ... onsubmit="return both_fields_filled()"> Note that you're returning the function return and not just running the function. |
|
#5
|
|||
|
|||
|
but the name of the Fuction is : check(), why I'm going to send to in the form,
form ... onsubmit="return both_fields_filled()"> I used form ... onsubmit="check()"> The problem is, the validate script is ok, but, If I don't enter any data in one field it must stay in the same page, until you complete the form, it run the : form... action.php... this is the site... prove it.. http://www.mailcreativo.com/loto/pale.php click "enviar" without to fill any field... I need to correct it... |
|
#6
|
||||
|
||||
|
If you don't use "return check()" the form doesn't evaluate the return value. It just executes the function and submits. If you return the function instead of just executing it, a false return will prevent the form from submitting and a true value will allow the form to submit. Try it.
Edit: I just saw that your problem wasn't necessarily with the return, but with the difference between check() and the function I referenced. My mistake. Try "return check()" and see if that works. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How to Control Fields |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|