View Full Version : Submit on Load
James67
12-10-2008, 10:38 AM
Hello
I wonder is anyone could help me with this problem. I have the following code :
<script language="javascript">
function form_submit() {
document.registration_form.operation.value = '';
document.registration_form.edit_refresh.value = '1';
document.registration_form.submit();
}
</script>
<input type="checkbox" name="tax_account_type" value="1" onclick="form_submit();" <? echo ($user_details['tax_account_type']) ? 'checked' : ''; ?>
When the checkbox is checked, the tax account type is obviously set to 1, the page refreshes and an additional tax registration field is displayed further down the web page.
I would like to remove the above checkbox altogether so the page loads with the additional tax registration field automatically. I assume i need to modify the function code so it changes the tax type on load but not sure of the precise coding.
Any help would be apreciated. :)
Many thanks
James
batterj2
12-11-2008, 07:47 AM
If you're going to remove the option that shows a second part of the form and make it default, doesn't that make the second part of the form automatically part of the whole form? Why not remove the checkbox and show the additional content when the page loads in the first place?
James67
12-11-2008, 10:18 AM
Hi James
The code doesn't seem to work that way.
By way of background the code relates to a registration page on a website and users have the choice of registering as individuals (default) or they can tick the checkbox to register as a business.
When they tick the checkbox their tax account type is set to 1 and the form submit function is triggered so the page reloads displaying a company name field. I have tried setting the tax account type = 1 as default in mysql and removed the if statement around the company name field (which is currently triggered when tax account type=1) but the form doesn't display the company name field.
Maybe I am missing something obvious but I think it has something to do with the form submit function. :(
batterj2
12-11-2008, 11:27 AM
Let me see if I've got this right:
User fills in the form.
If they are an individual they press submit and details are stored as normal
If they are a business they tick the Tax Account Type check box which submits the form and reloads it again with the details filled in but with the second part of the form in addition.
You want to remove the checkbox entirely and have the additional fields appear as default.
But if you do that it will assume ALL visitors are businesses, especially if you set the MySQL default value to 1?!
Surely to retain the same process logic you keep the checkbox (without the Javascript) and add the additional fields into the same form (copy paste) and add a bit of logic in your code (whatever it is) to check if the checkbox has been submitted - if not, its an individual otherwise its a business, store the additional values.
James67
12-11-2008, 12:29 PM
The original code assumed users were individuals but gave them the option to register as a business by clicking the checkbox. If they checked the box the page reloaded and the refreshed form added business name and VAT registration number etc.
My site is purely for business, so I need the default form to be the "refreshed" form i.e. the one with the business name and VAT boxes etc.
Since we last spoke, I have completely removed the checkbox and the "if" statements which surrounded the business name box and VAT box (rather than commented it out) and those boxes now display. The only trouble is, when the page is submitted the value of the tax_account_type which I set to 1 in mqsql is being overwritten with a zero (I assume this is because the checkbox has been removed so the form value is zero and its overwriting the default value of 1).
Is there a simple way to set the $user_details['tax_account_type'] = 1 (checked) in the code?
Many thanks
batterj2
12-11-2008, 12:39 PM
You could add a hidden field called tax_account_type and set the value to 1.
Otherwise edit the SQL statement to not insert the tax_account_type value and keep the default value to 1.
James67
12-11-2008, 01:48 PM
Many thanks !
Both methods work :)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.