Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Silly Javascript Function from onclick

    I want to have it so when a button is pressed in a form, to change that form's action
    heres the javascript

    Code:
    	function change2delete(name)
    	{
    		document.name.action='deletesong.php';
    	}
    and relevant html

    Code:
    <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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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:
    Code:
    function change2delete(name)
    	{
    		name.action='deletesong.php';
    	}
    .
    .
    onclick='change2delete(document.{$row['name']});'

  • Users who have thanked Fumigator for this post:

    Alphamonkey (08-28-2007)

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i fixed it, there was spaces in my string


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •