4 Replies - 447 Views - Last Post: 12 October 2011 - 11:22 AM

#1 epidemik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-June 08

How come my form goes to another page instead of staying on my form..

Posted 11 October 2011 - 02:33 PM

How come my form goes to another page instead of staying on my form page?

form code:

<form id="myForm" action="destination.cfm" method="post"> 
   <input type="submit" disabled id="submitButton" />
</form>

<script type = "text/javascript">

 // wait for the DOM to be loaded 
        $(document).ready(function() { 
            // bind 'myForm' and provide a simple callback function 
            $('#myForm').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); 
 
</script>



thank you for any help in advanced

Is This A Good Question/Topic? 0
  • +

Replies To: How come my form goes to another page instead of staying on my form..

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: How come my form goes to another page instead of staying on my form..

Posted 11 October 2011 - 03:04 PM

Hi,

I'm assuming that you are using the jQuery form plugin. If that is the case you want to use .ajaxSubmit() and return false. Something like:
            //execute this when the form submits
            $('#myForm').submit(function() { 
                //submit using the form plugin
                $(this).ajaxSubmit();
                //prevent the default action of the form submitting 
                return false;
            }); 



Something like that should do it :)
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: How come my form goes to another page instead of staying on my form..

Posted 11 October 2011 - 03:07 PM

I assume you included the jquery.form.js file into the page along with the jquery javascript file? If you didn't include those in the page, then the script there won't work and the form will submit as normal.

If you did include these files, show us the entire page so we can see perhaps where you made a mistake linking these files in.

:)
Was This Post Helpful? 0
  • +
  • -

#4 epidemik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-June 08

Re: How come my form goes to another page instead of staying on my form..

Posted 12 October 2011 - 09:44 AM

For some reason i still have an issue here is the full code for it:

    <script type="text/javascript" src="jquery-1.6.4.js"></script> 
    <script type="text/javascript" src="jquery.form.js"></script>
    
   <script type="text/javascript">
        setTimeout (function(){
        document.getElementById('submitButton').disabled = null;
        },10000);

        var countdownNum = 10;
        incTimer();

        function incTimer(){
        setTimeout (function(){
            if(countdownNum != 0){
            countdownNum--;
            document.getElementById('timeLeft').innerHTML = 'Time left: ' + countdownNum + ' seconds';
            incTimer();
            } else {
            document.getElementById('timeLeft').innerHTML = 'Ready!';
            }
        },1000);
        }
		
	
    </script>
    
</head>



<body onload = "setTimeout('enable()', 5000)">

<iframe width="560" height="340" src="http://cdn.livestream.com/embed/rlradio?layout=4&color=0xe7e7e7&autoPlay=true&mute=false&iconColorOver=0x888888&iconColor=0x777777&allowchat=true&height=340&width=560" style="border:0;outline:0" frameborder="0" scrolling="no"></iframe>





   <form id="myForm" action="auctionUP.cfm" method="post"> 


   Curent Price: 
      <input type="text" name="price" value="#price#" /> 
     <input type="hidden" name="user" value="user"/><input type="hidden" name="dollar" value="1">
 
     <input type="hidden" name="itemID" value="2">
     <input type="hidden" name="price" value="price">
    <input type="submit" disabled id="submitButton" />
</form>


<script type = "text/javascript">

//execute this when the form submits
$('#myForm').submit(function() { 
    //submit using the form plugin
    $(this).ajaxSubmit();
    //prevent the default action of the form submitting 
    return false;
}); 
 
</script> 


Was This Post Helpful? 0
  • +
  • -

#5 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: How come my form goes to another page instead of staying on my form..

Posted 12 October 2011 - 11:22 AM

Hi,

You may want to wrap that jQuery in a document.ready callback, or it's shorthand:
//when the document is ready
$(function(){
    //execute this when the form submits
    $('#myForm').submit(function() { 
       //submit using the form plugin
       $(this).ajaxSubmit();
       //prevent the default action of the form submitting 
       return false;
    }); 
}); 




Are you getting any errors? Try using a console.log or an alert to see if your submit callback is being called.

This post has been edited by Jstall: 12 October 2011 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1