General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 28th, 2003, 05:08 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
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

Reply With Quote
  #2  
Old September 28th, 2003, 07:00 PM
md2perpe md2perpe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 12 md2perpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
<script type="text/javascript">
function 
check()
{
    var 
document.forms.theform.thefield.value;
    if(
v>=&& v<=99)
        return 
true;
    else {
        
alert('Improper value!');
        return 
false;
    }
}
</script>

<form action="test.htm" method="get" name="theform" onsubmit="return check()">
<input type="text" name="thefield"/>
<input type="submit"/>
</form> 


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:
<?
if(! ($_POST['thefield']>=&& $_POST['thefield']<=99)) {
    
// Print error message and/or send visitor back to form
}
?>



Quote:
Originally posted by nestorvaldez
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.

Implement a Javascript function both_fields_filled() to return true if both fields are filled, false otherwise. Then use
PHP Code:
<form ... onsubmit="return both_fields_filled()"

Reply With Quote
  #3  
Old October 1st, 2003, 10:42 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
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..

Reply With Quote
  #4  
Old October 2nd, 2003, 08:00 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #5  
Old October 2nd, 2003, 05:00 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
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...

Reply With Quote
  #6  
Old October 3rd, 2003, 08:51 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > How to Control Fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT