...

View Full Version : Does button have to be type 'submit' ?



chonji
09-28-2011, 02:39 PM
Hi all, i have seen that there is an input type 'reset' which i presum clears all fields in a form? But anyway i did not know this existed and my implementation requires a bit more sophistication so i had already written code to do a custom reset of the boxes whilst keeping and updating certain key values. This works fine.

My question is, for the actual 'submit' of the data in a form do i have to use a button of type 'submit'? It is actually better for me in this instance that i do not as the special message windows i am using will close - and in the case of errors in the user input this is not desirable - so i have written the error handling etc with window staying open in mind, so that user can correct their errors and resubmit.

To accomplish this i changed my input into type 'button' and it works fine

When i click 'the submit button' it checks fields for valid data first - can i use its return value to somehow activate or not the actual form data sending?

Like i have


<input type = "button" style = "font-size:18;" value= " Submit "onclick = "CheckValid()"/>

I could be calling 'SendForm()' or something here instead and have check valid called from within SendForm() i norder to determin it's return type, how can i use this to decide if the form data is valid to send or not? and how could i use the return value in the html like this?

should i A: think it is possible to send all the data from within the onclick function so i use that to decide if it gets sent from internal calls there and display thank you message if so, if not display error message.

should i B:

Disable the sending button until the fields contain valid data? Or use a second button to confirm data then allow a submit button to be pressed?

xelawho
09-28-2011, 02:50 PM
if your checkValid function does what it seems to, why not just add an if else in there once the validation is complete?


if (valid==true) {
document.myform.submit();
} else {
//prompt user for more info
}

chonji
09-28-2011, 03:14 PM
if your checkValid function does what it seems to, why not just add an if else in there once the validation is complete?


if (valid==true) {
document.myform.submit();
} else {
//prompt user for more info
}

thats great - - Thats what i was looking for, now i know there is a document property that can submit the data then i can call that conditionally, and that is sorted.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum