FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Checking if input fields actually have input?

 


Diablosblizz
Hey, I was wondering if there was some simple way of checking if two (or more, which there will be when I start doing other forms) input forms are filled with something?

For example, if there is a form called "input" and two text fields called name and password is there anyway I can check if they have stuff in them? I tried this code below, but I can't see to get it working. :S

Code:
<script language="javascript" type="text/javascript">
      function submitbutton_reg() {
         var form = document.loginbox;

         // do field validation
         if (form.username.value == "") {
            alert( "Please enter your name." );
         } else if (form.password.value == "") {
            alert( "Please enter a User name." );
         } else {
            form.submit();
         }
      }
      </script>
   <h1>Login</h1>
   <div class="content">

<form action="login.php?page=login" method="post" name="loginbox">

Username:

<input type="text" name="username" size="32" maxlength="15" class="text" value="">

Password:<input type="password" name="password" size="32" maxlength="32" value="">

<input type="button" value="Login" class="button" onclick="submitbutton_reg()">


So that doesn't seem to be working. And I apologize, but I don't know much about Javascript, so I must learn some. Thank you, and kind regards.
coreymanshack
if(idname = ""){ //nothing in there}
elseif(idname = ""){//nothing in there}

just an idea^^

I usually don't do javacript, just php
rvec
first you have to know this is cliënt side, so this doesn't prevent hackers from entering the wrong stuff.
Second you only made a function, you have to start the function somewhere.

And if (form.password.value == "") {
alert( "Please enter a User name." );
if there is no password the user should enter a username? Razz
Diablosblizz
Sorry, this is just a draft. And I did start the function somewhere:

Code:
<input type="button" value="Login" class="button" onclick="submitbutton_reg()">


And I will fix the password thing, it's just something I found and attempted to edit but it doesn't seem to be working. Any other ideas?
rvec
i'd do it in php on the next page, on login.php?page=login .
But try to put the functionname in the form tag and use the same name as used in the script:
Code:
<form action="login.php?page=login" method="post" name="form" onsubmit="submitbutton_reg();">

I think it should work that way.
Diablosblizz
Yeah, I did it on the next page. Though, I dislike that because then I either have to include the login form on the page or make them go back and input their username or password.

Also, no it did not work the way shown. I tried many things, even looking at the Source of the reply page for PHPBB to see how they had it formatted. They had it the same way as I do.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.