ivy
02-07-2008, 04:25 PM
Hello all
The script I am having trouble with is supposed to do this:
After submitting a form's contents to itself, the php page adds the data to a mysql database for storing. Because the form submits to the same page, all the variables are still available and a new (blank) form appears to allow the user to continue adding data to the database.
I have put a checkbox on top of the form which says: "Use previous data".
Now, what should happen is that by using the below (not working!!!) script, the form is populated with the same data as previously entered (bar a couple of fields which will have to be unique - but that is besides the point).
So, this is how my page looks:
Within the form is the code:
Use previous data:
<input type="checkbox" name="copy"
OnClick="javascript:copyprevious(this.form);" value="checkbox">
And the javascript, which is WITHIN the body of the page (as I do not want it called within head (sorry - i know this is not the norm but just this time!!!):
<script type="text/javascript">
<!-- Begin
function copyprevious(form) {
if (form.copy.checked) {
form.tn_a.value = "<?php echo $tn_a; ?>";
form.tn_b.value = "<?php echo $tn_b; ?>";
form.tn_c.value = "<?php echo $tn_c; ?>";
}
else {
form.tn_a.value = 0;
form.tn_b.value = 0;
form.tn_c.value = 0;
}
}
// End -->
</script>
Now, here's the issue!!!
The form is composed of text areas, text boxes and radio buttons. I have had no problem inserting text (so I removed the code for that from above) but I cannot work out how to code the javascript so that the appropriate radio button within each group (e.g. tn_a) is checked. The variables coming from the php part of thinghs will all be numbers, e.g. 1, 2, 3 etc. And the form values for various radio items are valued 1, 2, 3 etc.
So, the end product should be the appropriate radio button checked within each group.
I hope I have made this clear.
Any help would be truly appreciated.
Many thanks
The script I am having trouble with is supposed to do this:
After submitting a form's contents to itself, the php page adds the data to a mysql database for storing. Because the form submits to the same page, all the variables are still available and a new (blank) form appears to allow the user to continue adding data to the database.
I have put a checkbox on top of the form which says: "Use previous data".
Now, what should happen is that by using the below (not working!!!) script, the form is populated with the same data as previously entered (bar a couple of fields which will have to be unique - but that is besides the point).
So, this is how my page looks:
Within the form is the code:
Use previous data:
<input type="checkbox" name="copy"
OnClick="javascript:copyprevious(this.form);" value="checkbox">
And the javascript, which is WITHIN the body of the page (as I do not want it called within head (sorry - i know this is not the norm but just this time!!!):
<script type="text/javascript">
<!-- Begin
function copyprevious(form) {
if (form.copy.checked) {
form.tn_a.value = "<?php echo $tn_a; ?>";
form.tn_b.value = "<?php echo $tn_b; ?>";
form.tn_c.value = "<?php echo $tn_c; ?>";
}
else {
form.tn_a.value = 0;
form.tn_b.value = 0;
form.tn_c.value = 0;
}
}
// End -->
</script>
Now, here's the issue!!!
The form is composed of text areas, text boxes and radio buttons. I have had no problem inserting text (so I removed the code for that from above) but I cannot work out how to code the javascript so that the appropriate radio button within each group (e.g. tn_a) is checked. The variables coming from the php part of thinghs will all be numbers, e.g. 1, 2, 3 etc. And the form values for various radio items are valued 1, 2, 3 etc.
So, the end product should be the appropriate radio button checked within each group.
I hope I have made this clear.
Any help would be truly appreciated.
Many thanks