0

Hello

I am new to JavaScript and need some assistance.

I am trying to create a page/form
where the user enters first and last name and select their title (Mr, Miss or Mrs).

There is also the ability to select 1 of 2 options by clicking a link.

After the name, title and option is selected the data is sent to the database using a submit button

The problem is when the link is selected and page refreshes and all the data is lost because the sticky page is not working.

<?
/**
   page: page_list_form.php
**/

include("../reqin/title_in.php");//title drop down

$option = $_REQUEST['u_source_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- <!DOCTYPE html PUBLIC "-//W3C/DTD//xhtml 1.0 transitional//EN"
  "http://www.w3.org/tr/xthtml1-transitional.dtd"> -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<title></title>

<script type="text/javascript">
//<![CDATA[

   function OnClick()
    {
      var title = document.getElementById('TitleId').value;

      calForm = document.getElementById("calendar");
      calForm.setAttribute("action", "<?=$_SERVER['PHP_SELF']?>?u_title="+title);

      calForm.submit(); // submit it, keeping POST vars

    }


//]]>
</script>

</head>
<body>
<form id="calendar" action="process.php>" method="post">

<?

 echo"<table><tr>
      <td width='30%'>
         <input type='text' name='first_name' value='$first_name' width='95%'/></td>";

 echo"<td width='30%'>
        <input type='text' name='last_name' value='$last_name' width='95%'/></td>

      <td width='30%'>";
           title($code);//dropdown with titles
 echo" 
  </td>
  <td>";

      /**display option selection**/
      if($option == "p1")
          {
            echo"Option One";
          }
         elseif($option == "p2")
          {
            echo"Option Two";
          }

 echo"<input type='hidden' name='option' value='$option'/>";//option value passed to database

 echo"</td></tr>
 <tr>";

 /**link to select and refresh page and keep title, first & last name **/
 echo"
     <td><div id='blue-listing'><a href ='../page_list_form.php?u_source_id=p1' onclick='javascript:OnClick();'>Option 1</a></div></td>
     <td><div id='blue-listing'><a href ='../page_list_form.php?u_source_id=p2' onclick='javascript:OnClick();'>Option 2</a></div></td>
     <td>&nbsp;</td>";

 /** submit data to database**/
 echo"<td><input type='submit' name='Submit'/></td>

  </tr></table>";

?>

</form>
</body>
</html>
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by assgar
0

Hello

I have made some changes that provise some hope.

When I select the link the sticky form works and the values are not lost.
The url display the value for the selected option. The is problem I am now having is with the

$option = $_REQUEST['u_source_id'];

it is not receiving the url value. The php if statement is not displaying the information related to the user selection.

<?
/**
   page: page_list_form.php
**/

include("../reqin/title_in.php");//title drop down

$option = $_REQUEST['u_source_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- <!DOCTYPE html PUBLIC "-//W3C/DTD//xhtml 1.0 transitional//EN"
  "http://www.w3.org/tr/xthtml1-transitional.dtd"> -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<title></title>

<script type="text/javascript">
//<![CDATA[

 function()
    {
    	document.getElementById('op_link').onclick = function()
    	  {
    	  	var form;
    	  	form = document.getElementById('calendar');
    	  	form.elements.link = this.href;
    	  	form.submit();
    	  };
    }

//]]>
</script>

</head>
<body>
<form id="calendar" action="process.php>" method="post">

<?

 echo"<table><tr>
      <td width='30%'>
         <input type='text' name='first_name' value='$first_name' width='95%'/></td>";

 echo"<td width='30%'>
        <input type='text' name='last_name' value='$last_name' width='95%'/></td>
      <td width='30%'>";
           title($code);//dropdown with titles
echo" </td>
  <td>";

      /**display option selection**/
      if($option == "p1")
          {
            echo"Option One";
          }
         elseif($option == "p2")
          {
            echo"Option Two";
          }

 echo"<input type='hidden' name='option' value='$option'/>";//option value passed to database

 echo"</td></tr>
 <tr>";

 /**link to select and refresh page and keep title, first & last name **/

 /** submit data to database**/
 echo"<td><input type='submit' name='Submit'/></td>

  </tr></table>";

?>

</form>
</body>
</html>

Edited by assgar: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.