Jump to content

Posting Javascript to Database Via PHP


Selacius

Recommended Posts

In a previous topic I asked how I could create a script where the numbers were dynamically increased without having to refresh the page. Anyways I have that script all figured out now, and I intend on placing it in a form with other text boxes for which I will need to insert into a database. I am curious, how can I go from a code like:

<tr><td>Strength:<td><center><div id="counters">4</div><td><a href="javascript:increments()"><b><center>+</a><td><a href="javascript:decreases()"><b><center>-</a>

where counters is the actual value of the number I want to insert into the database. So how can I do this using forms? Or rather, how can I supply these variables (counters...) to a php via a form.

Link to comment
Share on other sites

You want to insert the icremented number into a database using php without refreshing the page???There is only one way to do this that I know of...welcome to the world of AJAX.Read this article to understand what it is and how it works.http://rajshekhar.net/blog/archives/85-Ras...X-Tutorial.htmlThis is by far the best AJAX tutorial I have found.AJAX is basically a way to interact with teh server using javascript. It uses the HTTPXML object of the DOM to execute server functions from the client.

Link to comment
Share on other sites

No I didn't say I don't want to refresh the page. What I said is that my incremental number code does not require the refreshing of the page. The numbers and other user defined variables will be in a form, which will be redirected to a php page when the user submits the form. My question is, what do I change in the code which I pasted in the first post to allow the values to be carried over by the form.

Link to comment
Share on other sites

sorry for the misunderstanding.well assuming your final incremented value is now in a javascript variable called x... and you have a hidden field(input type="hidden" id="xNum">) in your form with the id xNum you can do this

document.getElementById('xNum').value = x;

now this will be sent with the form to your PHP page where you can retreive just like any other form field.

Link to comment
Share on other sites

The code is a lengthy piece of work, but mainly it is a form element in which the user inputs a few user defined values and also can play around with some numbers as well. The numbers in this example take the shape of a character creation system for an online game. There are 5 stats to which the user can increase and in doing so these values also increase the players beginning Hit points. This then all gets submitted to a final page via a form where the information can be inserted into a database for use in the game. If this is in any way/shape/form what you are looking for, feel free to PM me and I will gladly send you the code along with information on how to modify it to suit your needs. Many thanks goes out to aspnetguy on this forum and a few other forum members belonging to other forums.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...