LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   JavaScript & PHP (https://www.linuxquestions.org/questions/programming-9/javascript-and-php-191973/)

Gerardoj 06-10-2004 12:07 PM

JavaScript & PHP
 
Hi Guys I would like some on help on this form.

Hi I have the following function and It currently doesnt ask me for fill the blank field TeamName, What could be wrong?

Thanks a lot.
PHP Code:


function GetUserPredictions($user$Team$Copa$Nombre,$Equipo,$NombreEquipo,$Division) {

    
$link OpenConnection();
    if (
$link == FALSE) {
      echo 
"Unable to connect to the dbase";
      return;
    }

    echo 
"<form action=\"Ingresar-Apuesta.php\" method=\"POST\">";
    echo 
"<td  class=\"TBLROWER\"><font class=\"TBLROW\">$datestr $timestr</font></td>";
    echo 
"<input type=\"text\" name=\"TeamName\" value=\"$NombreEquipo\" >";

    echo 
"<input type=\"submit\" onSubmit=\"checkEquipo(this.form);\"name=\"Submit\" value=\"Submit\"></td>";
    echo 
"</form>";

    <
SCRIPT LANGUAGE="JavaScript">
    function 
checkEquipo(form) {
    if (
form.TeamName.value == "") {
    
alert("Fill the form");
    return (
false);
    }
            return 
true;
    }
     
</SCRIPT> 


paulsm4 06-11-2004 12:02 AM

Hi -

There are a couple of problems here:
1. I'd declare the javascript function *before* I use it.
2. Since you're initializing the text value with "$NombreEquipo", it might not be blank
... but the real problem is ...
3. Your onSubmit() method needs to go in the *form* tag (not "input type=submit").
Code:

<script language="JavaScript">
  function checkEquipo (f) {
    if (f.TeamName.value == "" || f.TeamName.value == null) {
      alert ("value empty!");
    }
    else {
      alert ("value= " + f.TeamName.value);
      return (true);
    }
  }
</script>
<form method="POST" onSubmit="checkEquipo (this);">
<table border="0">
<tr>
  <td>#/Equip:</td>$NombreEquipo
  <td><input type="text" name="TeamName" value="0"></td></tr>
<tr>
  <td colspan="2">
  <input type="submit" name="Submit" value="Submit"></td></tr>
</table>
</form>

'Hope that helps .. PSM


All times are GMT -5. The time now is 05:21 AM.