tags:

views:

117

answers:

3

For some reason it's not changing the action of the forum. I have some code to change the action of a form when a button is clicked:

    function changeForm(event){
    alert("Before: "+jQuery("#franchiseform").attr("action"));
    jQuery("#franchiseform").attr("action", "franchisepreview.php");
   alert("After: "+jQuery("#franchiseform").attr("action"));
    jQuery("#franchiseform").submit();
    }

The binding:

    jQuery("input.preview").bind("click", changeForm);

The form:

<form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform">

The buttons:

<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" /><input type="submit" value="Insert" />
A: 

Unless you stripped out too much, it looks like you need to put your "after" call into a function called "changeForm", which is what you are binding to the click event.

otherwise, keep chaining:

jQuery("input.preview").bind("click", function(){
    jQuery("#franchiseform").attr("action", "franchisepreview.php"));
    jQuery("#franchiseform").submit();
});
Cryophallion
Nope, it's in a function. I edited the original question.
Josh K
ok then, change the bind method to call to Jquery("#preview")
Cryophallion
And are the alerts just for testing? I would use firebug or similar to see if the click is changing things, and just keep the action change in the function, to make sure it is firing.
Cryophallion
I'm using Firebug as well, this is just easier then going into inspection view every time.
Josh K
+1  A: 

First off, you need to clean up the

<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" />

to:

<input type="button" value="Preview" id="preview" name="preview" />

as an input should not have multiple id attributes and you should not use classes and id's with the same name. This could be one reason why you're having problems. Then I used the following code and the action url was actually changing:

<html>
<head>
    <title></title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;

    <script type="text/javascript">
        $(document).ready(function() {

            $("#preview").bind("click", changeForm);

            function changeForm(event){
                alert("Before: "+ $("#franchiseform").attr("action"));
                $("#franchiseform").attr("action", "franchisepreview.php");
                alert("After: "+ $("#franchiseform").attr("action"));
                $("#franchiseform").submit();
            }   
        });
    </script>

</head>
<body>
    <form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform">
        <input type="button" value="Preview" id="preview" name="preview" />
        <input type="submit" value="Insert" />
    </form>
</body>
</html>
ryanulit
A: 

It turns out that this is a Firefox / Mac specific bug. It works on other platforms and browsers, but not this specific computer for some reason. It could be an extension conflict or something else, I'll simply use another browser.

Josh K
Just know that if this page is being used for public use then you are alienating a decent share of users.
ryanulit