PDA

View Full Version : Couple of problems with a form


jameshuk
03-20-2007, 01:35 PM
Hi Guys,

I have a couple of problems with a form I am working on.

1. If you press enter at any time it tries to send the form.... rather than jsut move onto the next section of the form(possible to change?)

2. I have a checkbox and i want to make it so that ticking it is required for the form to send. I jsut cannot work out how to do this?

Any help is VERY much appreciated!! I am a newbie at all this so the most basic explanation the better thanks"!

domedia
03-20-2007, 02:08 PM
Hi James and welcome to the forums!

1. This is how forms are supposed to work. If you change it, people will not be able to use your forms. In forms, the tab key sends you to the next section, and the enter key sends the form.

2. How did you try to do it? Code? URL?

jameshuk
03-20-2007, 02:21 PM
Hi James and welcome to the forums!

1. This is how forms are supposed to work. If you change it, people will not be able to use your forms. In forms, the tab key sends you to the next section, and the enter key sends the form.

2. How did you try to do it? Code? URL?



Hi and thanks for the response!

In answer to question 2. I have searched the internet for an explanantion without luck. Aside from that I tried through Dreamweaver and the behaviours panel but it didnt recognise my checkbox as something that could be considered required..... any suggestions are welcome!!!

It is for something along the lines of a terms and conditions ie. "click here to confirm you have read this statement" I jsut want it so they cannot send the form without ticking it!

Thanks!

davidj
03-20-2007, 02:25 PM
how are you processing the form data?

what language are you using

jameshuk
03-20-2007, 02:35 PM
Am processing the form using formail and the form itself was written in dreamweaver using with html.

Thanks!

davidj
03-20-2007, 02:44 PM
1. If you press enter at any time it tries to send the form.... rather than jsut move onto the next section of the form(possible to change?)

by pressing enter when in a form element will submit the form. In the world of the web you would navigate from element to element by using the mouse or TAB (there is a tab index attribute that can be used to order the tab sequence)


2. I have a checkbox and i want to make it so that ticking it is required for the form to send. I jsut cannot work out how to do this?


Not sure about the logic here. You want to tick a checkbox then click a button before the mail is sent? what happens if you dont tick the box but click the button?

jameshuk
03-20-2007, 02:47 PM
by pressing enter when in a form element will submit the form. In the world of the web you would navigate from element to element by using the mouse or TAB (there is a tab index attribute that can be used to order the tab sequence)



Not sure about the logic here. You want to tick a checkbox then click a button before the mail is sent? what happens if you dont tick the box but click the button?

If I currently dont tick the checkbox then the form sends anyway.

What I want to happen is that if the checkbox isnt ticked then when the button is pressed the form doesnt send and a message saying please tick the checkbox comes up....?

Like when you register for this board you have to tick the box saying you are over a certain age and have read the terms and conditions....

Thanks again

davidj
03-20-2007, 03:00 PM
gotcha

ok you want a simple javascript function

1.) turn the button in the form to a button type instead of a submit.

2.) create a checkbox and call it terms and also give it an id = "terms".

3.) create a <div id="msg"></div> and place in the page where you want the warning to appear

4.) on the form button add the function call

example..
<input type="button" name="Button" value="Button" onclick="submitter()"/>

here is the JS function

<script >

function submitter(){

chk = document.getElementById('terms');
msg = document.getElementById('msg');

if(chk.checked == true){

document.forms[0].submit();

}else{

msg.innerHTML = "warning. You need to accept the terms and conditions";

}

}
</script>

jameshuk
03-20-2007, 03:06 PM
Thanks David!! You have no idea how long I have been trying to find a simple explanation like that!!

Thanks again for all your help and I look forward to enjoying posting on the forums in the future!

domedia
03-20-2007, 04:57 PM
Dreamweaver has form validation already. Click your form element and go to behaviours->Validate Form

davidj
03-20-2007, 04:58 PM
its shite

better off writing your own

domedia
03-20-2007, 05:45 PM
happens every time you add an abstract layer ;)

It's great for people to that can't script though.