Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Old 09-20-2012, 02:48 PM   PM User | #2
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
FWIW - think I've solved it with a separate function and eval():

Code:
<input type="button" id="butt" value="Go" onClick="whiskaway('<?=$d['ID']?>');" />

<script>
function whiskaway(n) {
  var f = "dupDetail.php?id=<?=$d['ID']?>&dt=" + eval("document.getElementById('dupdate<?=$d['ID']?>').value");
  parent.location=f;
}
</script>
rainjam is offline   Reply With Quote
Old 09-20-2012, 03:15 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
1. You cannot give a name or id to any element that begins with a number; it must begin with a-z or an underscore.
2. eval() is evil, do not use it, it is JavaScripts executable environment and not only is it slow, but it opens your site to security issues.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Tags
forms, javascript, onclick

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 AM.


Advertisement
Log in to turn off these ads.