![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 6
Rep Power: 0
![]() |
ok...
im A TOTAL beginner at this so how do i make it so when someone presses submit button and they havent filled in a form a alert message comes up and does not allow for them to continue. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
you're gonna need to use JavaScript to make an actual pop-up, you can use PHP to display a message, but you can't do pop-ups with PHP. search google, there's a lot of information, and examples out there.
good luck Dizz |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
You could use javascripts to check the form values.
this is what i use. i got it off of some website somewhere, i can't remember which. <script language="JavaScript">
function checkrequired(which)
{
var pass=true;
if (document.images)
{
for (i=0;i<which.length;i++)
{
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required")
{
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0))
{
pass=false;
break;
}
}
}
}
if (!pass)
{
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
{
return true;
}
}
</script>Then to use it in your form do this: <form method="post" action="MyAction" onsubmit="return checkrequired(this);"> <input type="text" name="requiredName"> <input type="submit" value="Continue"> </form> The important part is that you put required infront of all the fields that you want to be checked. Also you need the onsubmit part so the script gets run when the user submits the form.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2004
Posts: 6
Rep Power: 0
![]() |
oh thanks for the code.
its working =) |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
however, know that someone can simply type:
javascript:void(checkrequired = function() {return true;}); To get past that, you need code on the server-side to truly check to make sure that the values have been entered or not. Client-side code is unreliable.
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|