View Single Post
Old 09-20-2012, 02:06 PM   PM User | #1
rainjam
New to the CF scene

 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
rainjam is an unknown quantity at this point
Using Javascript to kludge together a nested form

I have a maintenance page which loops through records and displays each field as an editable text box - there's one Submit button at the end which allows changes to all or any of the data on the page:

Code:
// Pseudocode for simplicity
<form>
while ($d = mysql_fetch_assoc($sql)) {
<input type="text" name="date" value="$d['date']" />
<input type="text" name="1" value="$d['val1']" />
<input type="text" name="2" value="$d['val2']" />
[...]
}
<submit button>
</form>
I want to be able to add a "duplicate this record" option at the end of each line, which will allow you to select a new date and then copy all the rest of the data from that line into that date. Since it will already be inside a <form>, I can't put this in another <form>, so I'm trying Javascript:

Code:
// Pseudocode for simplicity
<form>
while ($d = mysql_fetch_assoc($sql)) {
<input type="text" name="date" value="$d['date']" />
<input type="text" name="1" value="$d['val1']" />
<input type="text" name="2" value="$d['val2']" />

<input type="text" value="" name="dupdate<?=$d['ID']?>" id="dupdate<?=$d['ID']?>" onchange="document.getElementById('butt').onClick = 'parent.location = \'dupDetail.php?id=<?=$d['ID']?>&dt=this.value\';' ">
      <input type="button" id="butt" value="Go" onClick = "parent.location = 'dupDetail.php?id=<?=$d['ID']?>' " />
[...]
}
<submit button>
</form>
I think the sticking point is the changing "parent.location" bit. All I need is that when the text box is changed, the URL the button redirects to will change to include this new value. It doesn't give any error messages in the console (I'm using Firefox at the moment) so with my limited Javascript I'm a bit stuck!
rainjam is offline   Reply With Quote