3

I have a small question, which I guess in my opinion will sound stupid. I have actually this code

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

var email_value = prompt('Please enter your email address');
if(email_value !== null){
//post the field with ajax
$.ajax({
    url: '="/new/cfolder.php',
    type: 'POST',
    dataType: 'text',
    data: {data : email_value},
    success: function(response){ 
     //do anything with the response
      console.log(response);
    }       
}); 
}

});
</script>

I would like to link it to my button which does this

<form action="/new/cfolder.php" method="post">
    </font><input type="submit" value="Create Vdisk" class="myButton6" onClick="function()"> 
<br></form>

Is it actually possible to do this? thank you for any answer.

0

3 Answers 3

1
 <script type="text/javascript">
  $(document).ready(function(){
    $(document).on('click', '.myButton6', function(){
      var email_value = prompt('Please enter your email address');
      //post the field with ajax
      if(email_value.length > 0){
        $.ajax({
            url: '/new/cfolder.php',
            type: 'POST',
            dataType: 'text',
            data: {data : email_value},
            success: function(response){ 

              alert(response);
            }       
        }); 
      }
    )};
  }); 
</script>

try that way

Sign up to request clarification or add additional context in comments.

Comments

0
// this is the id of the form
$("#idForm").submit(function() {

var url = "path/to/your/script.php"; // the script where you handle the form input.

$.ajax({
       type: "POST",
       url: '="/new/cfolder.php',
       data: $("#idForm").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data); // show response from the php script.
       }
     });

return false; // avoid to execute the actual submit of the form.
});

give your form an id

<form id="idForm" action="/Same/path/as/your/ajax/" method="post">
</font><input type="submit" value="Create Vdisk" class="myButton6" onClick="function()"> 
<br></form>

Comments

0
Yes of course you can do this . Like  this code and you will have to include jquery1.9.0.js or above.


 <script type="text/javascript">
    $(document).ready(function(){
    $("#myButton6").click(fuction(){
    var email_value = prompt('Please enter your email address');
    if(email_value !== null){
    //post the field with ajax
    $.ajax({
        url: '/new/cfolder.php',
        type: 'POST',
        dataType: 'text',
        data: {data : email_value},
        success: function(response){ 
         //do anything with the response
          console.log(response);
        }       
    }); 
    }

    });

    });
    </script>
    I would like to link it to my button which does this


 </font><input type="submit" value="Create Vdisk" class="myButton6" id="myButton6"> 
    <br>

1 Comment

I've done what you've did but it just refresh my page.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.