Form Anchoring.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Form Anchoring.

Post by quadoc »

Hi, I've a forms with some inputs and one of the inputs is a Drop Down List. What happen is I have to scroll the form down to select from to the Drop Down List and make a selection. When I did this, my form jump back to top like when I first entered the page. I've used anchoring like below but it doesn't look like it's working. Could someone takes a look a the script and let me know what I did wrong. Thanks

Code: Select all

<?php
include "online.php";
?>
<SCRIPT LANGUAGE=javascript>

function selDept(obj)
{
   document.getElementById("hidDept").value=obj.options[obj.options.selectedIndex].value

   if(document.getElementById("hidDept").value!="")
   {					
      document.getElementById ("frmDept").submit()
   } 
}


</SCRIPT>

<form name="frmDept" id="frmDept" method="post" action="http://MyForm.com/NewTicket">
  <input type="hidden" name="hidDept" id="hidDept" value="<? echo $tmpDept; ?>">
</form>

<form name="frmTicket" method="post" enctype="multipart/form-data">

  <table width="650" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr align="left" valign="top"> 
      <td colspan="2">
		<table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><strong>Submit a support ticket<br>
              </strong><img src="images/submitticket.png" width="54" height="54"></td>
            <td width="45" align="center" valign="top"><a href="index.php?x=home"><img src="images/back.png" width="54" height="54" border="0"><br>
              Back</a></td>
          </tr>
        </table>
      </td>
    </tr>

    <tr align="left" valign="center"> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    
	<tr align="left" valign="center"> 
      <td ><font color="#<? echo $fontname ?>">User Name</font></td>
     <td width="450"> 
        <input name="name" type="text" id="name" value="<?php if(isset($_SESSION["name"])){ echo $_SESSION["name"]; } ?>" disabled maxlength="50">
      </td>
    </tr>
    
	<tr align="left" valign="center"> 
      <td width="130"><font color="#<? echo $fontemail ?>">E-mail</font></td>
      <td> <input name="email" type="text" id="email" value="<?php if(isset($_SESSION["email"])){ echo $_SESSION["email"]; } ?>" maxlength="50"></td>
    </tr>
    
<tr align="left" valign="center"> 
      <td width="130"><font color="#<? echo $fontsubject ?>">Subject</font></td>
      <td><input name="subject" type="text" size="60" id="subject" value="<?php if(isset($_SESSION["subject"])){ echo $_SESSION["subject"]; } ?>" maxlength="120"></td>
    </tr>

<a name='$Counter'></a>    

    <tr align="left" valign="center"> 
      <td><br><font color="#<? echo $fontdep ?>">Department</font></td>
      <td><br>
	  <select name="department" id="department" onchange="javascript:selDept(this)">

<!--    <select name="department" id="department" onchange="javascript:putValue()">  -->
 <?php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to get to the only anchor I see in the code, you'd have to use a URL like this (literally) foo.php#$Contact php will not parse your variable, if that's what you are after.. :)
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

so I'd have to make my URL like this?

Code: Select all

<form name="frmDept" id="frmDept" method="post" action="http://MyForm.com/NewTicket#$Counter"> 
  <input type="hidden" name="hidDept" id="hidDept" value="<? echo $tmpDept; ?>"> 
</form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

provided http://MyForm.com/NewTicket is the URL of that script..
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

My other question is I only want this page to scroll down if only the user have made a selection from the Drop Down List though. I don't want it to scroll down when the user first enter the page. How'd I do that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

link to it like normal.. no hash
Post Reply