1.

Solve : VerY Basic?

Answer»
When i press Submit I want it to writeout my FirstName and Lastname.. it coud be on a iframe, ANOTHER page or something...






First name:           

Last name:          






Code: [SELECT]
<?php

if(isset($_POST['FirstName']))
  echo $_POST['FirstName'];
if(isset($_POST['LastName']))
  echo $_POST['LastName'];

?>

<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

First name:        <input type="text" name="FirstName" />   

Last name:       <input type="text" name="LastName" />   


<input type="submit" value="Submit" />
</form>

</body>
</html>

Assuming you have a PHP TEST server set up. If you're going to use this anywhere online, it's better to validate the data before displaying on a page - but this is the basic way of doing it.i dont use php...

u know with javascript? Code: [Select]<html>
<head>
  <script type="text/javascript">
    function open_window() {
      var first_name = document.getElementsByName("FirstName").value;
      var last_name = document.getElementsByName("LastName").value;
      myWindow = window.open('','','width=500,height=400');
      myWindow.document.write("<p>First name: "+first_name+"</p>");
      myWindow.document.write("<p>Last name: "+last_name+"</p>");
      myWindow.focus();
    }
  </script>
</head>
<body>

<form onsubmit="open_window()">
  First name: <input type="text" name="FirstName" />   
  Last name: <input type="text" name="LastName" />   
  <input type="submit" value="Submit" />
</form>

</body>
</html>

That should work...thnx but it doesnt work...
When i write my Firstname and lastname it STILL says:


First name: undefined

Last name: undefinedWorks now...

Code: [Select]<html>
<head>
  <script type="text/javascript">
    function open_window() {
      var first_name = document.getElementById("FirstName").value;
      var last_name = document.getElementById("LastName").value;
      myWindow = window.open('','','width=500,height=400');
      myWindow.document.write("<p>First name: "+first_name+"</p>");
      myWindow.document.write("<p>Last name: "+last_name+"</p>");
      myWindow.focus();
    }
  </script>
</head>
<body>

<form action="#">
  First name: <input type="text" id="FirstName" />   
  Last name: <input type="text" id="LastName" />   
  <input type="submit" value="Submit" ONCLICK="open_window()" />
</form>

</body>
</html>


Discussion

No Comment Found