Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with feedback form

Status
Not open for further replies.

MHUK

Programmer
Nov 30, 2002
139
GB
Hi

I have just created a simple feedback form for a person requesting an information brochure using PHP. Everything works fine. However there is a problem...when the user clicks the link on my home page which is just a button taking them to the Brochure Request page, when the Brochure request page opens up it opens up with the first input field at the very top of the page. As a result the very top of the page is missed out, and the user has to scroll up to see it. Is this some kind of default action to do with where the cursor is in the input field?

The code for the first 2 input fields is as follows:

<tr><td>
<label for "sub">Subject:</label>
</td>
<td><INPUT class="text" TYPE="TEXT" SIZE="28" NAME="sub" value="Information Brochure Request" title="You do not need to edit this field">
</td></tr>
<!--FIELD2 EMAIL**************-->
<tr><td>
<label for="email">Your email address:</label>
</td>
<td>
<INPUT class="text" TYPE="TEXT" SIZE="28" NAME="email" value="<? echo $email; ?>" title="Please enter your email address">
</td></tr>

Essentially the first input field is filled in by default as the subject heading called "Information Brochure Request", and the second input field is left empty for the user to enter their email address. However I was not sure how to make the first input field read-only so the user could not edit it, but yet the value of the field would still remain - the value being the text: "Information Brochure Request". The cursor still flashes in the first input field. Is it a case of changing the 'type' of field from 'input' to something else?

However onto my main problem - why when the user clicks into the page does it start from the first input field instead of the top of the whole page as normal? Is it something to do with the fact I have already entered a value in the first input field?

Thank you for any help or insight into solving my two problems.

MHUK
 
This is a HTML Question, but an advance... anyway you should ask there.

1. <INPUT class="text" TYPE="TEXT" SIZE="28" NAME="sub" value="Information Brochure Request" title="You do not need to edit this field">

add "disable" to the INPUT tag.

<INPUT class="text" TYPE="TEXT" SIZE="28" NAME="sub" value="Information Brochure Request" title="You do not need to edit this field" disabled>

user can not edit this input with "disable".

2. Add a little javascript at the end of the page with:

<script>
document.form.email.focus()
</script>

with this, every time you load the page, the cursor will be in the email input.

3. where are the "<form></form>" tags? that could be your problem?

Cheers.
 
Hi

Thank you for your reply. I will use the disabled keyword to stop the field being edited.

The form tag is a little further up the page and reads as follows:
<FORM name=emailform onsubmit="return emailCheck(this.email.value);" ACTION="feedback1.php" METHOD="POST">

I have just tried the
<script>
document.form.email.focus()
</script>
and it changes the cursor position to another field, a textarea field, which is called 'text' which is used for customer comments. I am not sure why the focus moves to this field and not 'email'.

However it seems to be the focus() that is causing the problem of why the screen when opened only starts from where the cursor is. Is there someway of removing focus altogether?

Thank you for your help.

MHUK
 
you could focus to cursor to the first input tag. By default, the cursor is not focused in inputs. Are you sure you have no scripts beside the posted by me?

In addition, could you post the inputs of the form? is quite weird the focus issue.

BTW, Add "language=javascrip" to the script tag:

<script language="javascript">
document.form.email.focus()
</script>

for standard.
 
Hi I seem to have sorted it out. There was some other code which I forgot about which was setting the focus to the comments box. However the 'disabled' keyword in the input field for 'Subject' does prevent the field being edited but the value does not get passed across.

Here is the input field I am referring to
><INPUT class="text" TYPE="TEXT" SIZE="28" NAME="sub" value="Information Brochure Request" title="You do not need to edit this field" disabled>

The disabled keyword does prevent the field being edited which is good but it prevents the value of "$sub" being passed across when I try to pick it up.

Is there an alternative to 'disabled' to make a field read-only but still allow the variable value in the field to be passed across?

Thank you for any help.

MHUK

 
<input class="text" type="text" size="28" name="sub" value="Information Brochure Request" title="You do not need to edit this field" readonly />

or in xhtml:

<input class="text" type="text" size="28" name="sub" value="Information Brochure Request" title="You do not need to edit this field" readonly="readonly" />

But the trouble with readonly is that is a rather new attribute and it is not supported by older (4th gen) browsers - they will still be able to change the field.

Alternative is

<input class="text" type="hidden" size="28" name="sub" value="Information Brochure Request" title="You do not need to edit this field" />

if you do not need the field to be shown, the value will be passed and since it is hidden, nobody can change the value.
 
Ok thanks for your help. I'll probably use the hidden option.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top