|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
checkbox to govern dynamic form fields
I am working on a form in php/HTML that gathers input from a user that is then written to a mySQL database. I need something similar to what is used on so many web sites where you are asked whether your billing address is also your ship to address and if you check yes, the shipt to fields are auto filled with what you have put in for the billing fields. I am using a checkbox on the form that I want the user to check if two addresses are the same. If the user checks the box, I want the second address fields (newfield) to be autofilled based on the first address fields (oldfield).
I tried doing it with an onClick embedded in the HTML where I check that the value of the checkbox is checked and then I set the newfield.value=oldfield.value. I don't have the code on this machine so I'm not posting it tonight but when the box is checked, no auto population is occuring from the old address fields that are filled in already to the second address fields that have not been filled in. I am sure this is not a difficult task and I assume it can be done with only HTML and php or do I need to look at using js? Thank you |
|
#2
|
|||
|
|||
|
RE: checkbox to govern dynamic form fields
usually, you can just use the same variables/fields to insert values into your DB.
try writing a script which runs this algorithm. if billing chkbox = true, use the same values for billing address from shipping address. consequently, you can tag these entries with a flag called bill_ship or something similar. |
|
#3
|
|||
|
|||
|
RE: checkbox to govern dynamic form fields
Well, you are definitely going to have to use javascript for the autopopulation. PHP pretty much wont help you in this case because all of its parsing is done server side. It will be a greater help when you post the code. I would be more than happy to write some javascript to accomodate that for you.
|
|
#4
|
|||
|
|||
|
Message Moved
Thread moved from 'PHP Coding' to 'Client Side Things' by nawlej.
Reason: form population issue....... |
|
#5
|
|||
|
|||
|
RE: checkbox to govern dynamic form fields
You might want to try prefixing the call in you onclick event with javascript:
I have noticed things will sometimes not work correctly without it. Another thing is to put document.form_name. in front of the field names. Last, you could put the code to do this in a function and call that function from the onclick event. This is probably not necessary if you are only copying one value. |
|
#6
|
|||
|
|||
|
RE: checkbox to govern dynamic form fields
Played around with it.. this should work!!!
Code:
<form name="testform">
Address 1 : <input type="text" name="address1"><br>
Address 2 : <input type="text" name="address2"><br>
<input type="checkbox" onClick="if(this.checked==true) { document.testform.address2.value=document.testform .address1.value; } else { document.testform.address2.value=''; }">
</form>
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > checkbox to govern dynamic form fields |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|