submit button

liunx

Guest
hi<br />
<br />
im making a form page, and am just wondering why when the user goes to click on the submit button that they can also click outside the button to dp the same function. the clickable area seems to take up the whole row of where the submit button is.<br />
<br />
here is the code<br />
<br />
<SCRIPT LANGUAGE="javascript"><br />
<!--<br />
function check() {<br />
g=document.declaration;<br />
if(g.disagree.checked==true && g.agree.checked==true){<br />
alert("You cant tick both boxes!");<br />
return false;<br />
} else if(g.disagree.checked==true){<br />
alert("You can't proceed");<br />
return false;<br />
} else if(g.agree.checked==true) {<br />
return true;<br />
} else {<br />
alert("You havent ticked a box!")<br />
return false;<br />
}<br />
}<br />
<br />
//--><br />
</SCRIPT><br />
<br />
<!--Start of declaration form--><br />
<br />
<form name="declaration" action="applications.html"><br />
<br />
<center><br />
<input type="checkbox" id="disagree" value="declaration" />Disagree<br />
<input type="checkbox" id="agree" value="declaration" />I agree<br />
<br />
</center> <br />
<br />
<br><br />
<br><br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"applications.html" onClick="return check();"><br />
<br />
<center><br />
<br />
<input type="submit" value="Begin" name="applications" align="right" ><br />
<br />
</center><br />
<br />
</a><br />
<br />
</form><br />
<br />
<!--End of form--><!--content-->I guess I'm not sure why you would need to enclose the submit button in the anchor tag. I know you're doing it for some sort of validation purpose, but you might be better off calling the check() function from the button itself. Just change the type attribute to "button" and move the onclick event to the INPUT tag.<br />
<br />
Then after the JavaScript has determined that everything checks out, just do a document.declaration.submit() to have the script submit the form, instead of the button.<br />
<br />
If you need to direct the user to a different page after submitting the form, you can always add a window.location ="URL_HERE"; to the script. It looks as though the form's action will take you to application.html without any interference from the script anyway.<!--content-->thanks gar for your speedy reply but i am still a bit confused as to where some of the code actually goes.<br />
<br />
where do i put the<br />
<br />
document.declaration.submit()<br />
<br />
is it a new function??<br />
<br />
<br />
and where would i put<br />
<br />
window.location ="URL_HERE"; <br />
<br />
in the same function??<br />
<br />
as you can see im not a java expert<br />
<br />
thanks mate<!--content-->Originally posted by dennic <br />
the clickable area seems to take up the whole row of where the submit button is.<br />
<br />
<br />
The reason it is like this is becuse you tell the browser to do this.<br />
<br />
<a><br />
<center><br />
button<br />
</center><br />
</a><br />
<br />
To start with, that is compleatly illegal code. You are not allowed to place a block-level CENTER inside an inline-level A.<br />
<br />
The browser error correction apparently recovers from this error by also making A blocklevel, which means it will span the entire width of the row.<br />
Remove the center and it will not happen.<!--content-->
 
Back
Top