3

When I want to submit a form with my js i always get this error:

Uncaught TypeError: Cannot read property 'submit' of null

its like the js doesnt find the form

Here the js code:

echo "<script language='javascript' type='text/javascript'>";
echo "function send(ak,id){";
echo   "document.getElementById('java').submit(); ";
echo "document.write('submited');";
echo"}";
echo "</script>";

And here the php / html:

   echo "<form id='java' method='post' action='reisegruppe.php' >";
   echo "<input name='ak' type='hidden' />";
   echo "<input name='id' type='hidden' />";    
    
// Reisegruppe ausgeben
if ($result1->num_rows > 0) {
    // Reisegruppe ID , von , nach ausgeben
    $count = 1;
    while($row1 = $result1->fetch_assoc()) {
        
        echo "<br>" . "id: " . $row1["reisegruppe_id"]. 
             " - <b> von: </b> " .'<b>'.'<input name="von" value='.$row1["von"].' size="5" />'.'</b>'. " " .
             "<b>nach: </b>" .'<b>'.'<input size="5" name="nach" value='. $row1["nach"].'>'.'</b>'." ". "<br>";
     
        echo "<a href='javascript:send(1,32)';>neu eintragen</a>";
        
      
        while($row = $result->fetch_assoc()){     
            if($row1["reisegruppe_id"] == $row["FK_reisegruppe_id"]){                
           echo  " - Name: " . $row["vorname"]. " " . $row["nachname"]. " " . "<br>";}    
        }
        
        $sql = "SELECT reisegruppe_id, von, nach,teilnehmer_id, vorname, nachname,FK_reisegruppe_id FROM Reisegruppe JOIN Teilnehmer on FK_reisegruppe_id = reisegruppe_id";
$result = $conn->query($sql);
          
    }
    
} else {
    echo "0 results";
}


echo </form>;

7
  • The last PHP line should be echo '</form>'; otherwise the form is not completed and does not exist. Commented Oct 27, 2015 at 9:25
  • echo "</form>"; it is at the end Commented Oct 27, 2015 at 9:32
  • are you executing your javascript code BEFORE the form was't actually created. Or after form Commented Oct 27, 2015 at 9:35
  • im executing it with the link : echo "<a href='javascript:send(1,32)';>neu eintragen</a>"; there the form already exists Commented Oct 27, 2015 at 9:42
  • echo "document.write('submited');"; remove this line and ur function is good to go.. Commented Oct 27, 2015 at 9:47

1 Answer 1

2

comment this line because it is stop the from from submitting

echo "document.write('submited');"; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.