1

I've built a function that rotates a picture when you click a button. I would like to tell this function how many degrees I want it to rotate with a text field or something like that and also call a function that's being executed in php that moves a stepper motor. Is there a way to do so? I've tried with a submit button but it doesn't show the animation the way I want to.

0

1 Answer 1

1

Submit button are generally used to submit forms. Although you can use them too, its not recommend. You can simply use <button /> element. And you can pass the function parameter on the onclick event handler of the button.

<button id="rotate" onclick= "rotate('35')">Rotate</button>

If you want to get value of text field and send in the form.

<button id="rotate" onclick= "rotate(document.getElementById('textboxid').value)">Rotate</button>

Demo

However, calling a function being executed over PHP is a tricky part. There are different ways you can do that:

  • Submit the form to the PHP page and assign URI parameters like page.php?function=test
  • Direct to the PHP page with passing the values in the URI parameters similar to above.
  • Use AJAX request to send and receive data.
Sign up to request clarification or add additional context in comments.

4 Comments

I've tried that, but how do I get the number from the text field without submitting it?
Thank you, but I'm actually fairly new at this and I don't really know how to assign URI parameters nor use AJAX... could you please write an example with this?
@YogeshSuthar, What makes you so sure, I wrote it from your comment? It is a well know fact.
@EdnaRamirez, That will make the answer really long and off topic also. How about take a step up and try jQuery. Read the jQuery's post request here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.