...

View Full Version : Silly Javascript Function from onclick



Alphamonkey
08-28-2007, 04:49 AM
I want to have it so when a button is pressed in a form, to change that form's action
heres the javascript


function change2delete(name)
{
document.name.action='deletesong.php';
}

and relevant html



<form name='{$row['name']}' method='post' action='editsong.php' enctype='multipart/form-data'>" .

<input type='submit' name='button' id='button' value='Edit'>
<input type='submit' name='delete' id='delete' value='Delete' onclick='change2delete({$row['name']})'>
</form>



there is nothing wrong with the $row['name'], i have left out my mysql conncetion and testing to see if they all contain values

Fumigator
08-28-2007, 05:25 AM
You want to pass a reference to the actual form object, not the string of the name. document.name.action does not know you want to substitute "name" with the value being passed to the function.

So do this instead:


function change2delete(name)
{
name.action='deletesong.php';
}
.
.
onclick='change2delete(document.{$row['name']});'

Alphamonkey
08-28-2007, 06:03 AM
well that worked....kindof

let me elaborate

i have a while loop getting rows from a msql table if you already haven't guessed. and so far, i have three rows...so when i display the page there are three edit and delete buttons

the delete only works with the second row strangly...

you have an answer to this...this is way over my head now

Alphamonkey
08-28-2007, 03:49 PM
i fixed it, there was spaces in my string



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum