Forum Moderators: coopster & phranque

Message Too Old, No Replies

How to start mid-page in CGI generated page?

         

Learning Curve

7:30 pm on Mar 1, 2003 (gmt 0)

10+ Year Member



I'm planning to write an error page for a form ("You forgot to fill in...") and I would like the new form page to have already scrolled down to the missing input field and error message when the CGI generated page is finished loading.

Any ideas?

Birdman

7:45 pm on Mar 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe you could output a jump-to link(s) at the top of the page llike this:

You forgot your name. <a href="/yourpage.html#name">Click here to fix</a>

<input type="text" name="name" id="name" />

ga_ga

2:42 am on Mar 3, 2003 (gmt 0)

10+ Year Member



I haven't a clue if this works, but also you could try a javascript focus()

eg

.
.
.
<body onLoad="javascript: document.foo.offendingBox.focus()">
.
.
.
.
<form id="foo">
<input type="text" id="offendingBox">
</form>
.
.

you'd have to get the error handling to write out the page appropriately with the correct form element id in the onLoad script

hope it might help. if not sorry for a time-waste

Learning Curve

2:30 pm on Mar 3, 2003 (gmt 0)

10+ Year Member



Thanks for the responses.

Is there any other way besides javascript or user click?

jatar_k

2:48 pm on Mar 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can give each field a target as Birdman said and then when you give your error you can use the script to jump to the offending field.

It really depends on the method you are using for error delivery. If you are reloading the form in the same page you could use a js onload to give focus to the field.

Or if you are using a "go back to fix it" link then you could have the back link target the field.

hakre

3:51 pm on Mar 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you can dynamically show the form. if the input is ok, put it into a hidden field (or store in session vars) and display only the fields again with missing or incomplete data and a description about whats missing. this method can handle multiple wrong inputs, too.

Learning Curve

4:40 pm on Mar 3, 2003 (gmt 0)

10+ Year Member



hakre, I had't thought of that. It would probably be easiest for the user to understand.

Great ideas all around. Thanks everyone.

hakre

6:22 pm on Mar 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for thanks ;)

what i really like on more complex forms if i get a page afterwards which displays my input in a simple way so i can check it out at the end before the final submit. that's maybe a good idea if you make your forms interactive.