Page 1 of 1
mySQL query using script
Posted: Tue Oct 25, 2005 2:31 pm
by kristolklp
I would like to run a function when a user checks a checkbox to update a fields in a database. I know to call a function using 'onCLick' you have to write a function through script, however I am unsure how to or if you can then run a query in Javascript.
Will I need to use VBScript instead?
Any help (or a quick example) would be greatly appreciated.
Thanks.
*edit: sorry, i meant to post this in the database section.
Posted: Tue Oct 25, 2005 3:09 pm
by feyd
vbscript, nor any other client-side scripting language can do it. You would use the onclick to do a form submission with the important data to a script on the server that performs the action requested..
Posted: Tue Oct 25, 2005 3:22 pm
by kristolklp
oic...thanks for the quick reply.
How do i submit a form using onClick? This is how I was calling my function.
Code: Select all
<input type="checkbox" name="update" onClick="UpdateSetting();">
Is it as simple as doing:
Code: Select all
<input type="checkbox" name="update" onClick="document.formName.submit();">
Posted: Tue Oct 25, 2005 3:29 pm
by feyd
you can do it in the function or like the latter.. it's quite flexible as to where you can do it..
Posted: Tue Oct 25, 2005 3:31 pm
by RobertGonzalez
No, I think Feyd is trying to tell you that the server needs to handle the processing not the client machine. That means that the onClick event will not generate the results you want because a client side script cannot interact with a database.
Process the form as normal and handle the database interaction with the server-side script.
Posted: Tue Oct 25, 2005 3:50 pm
by kristolklp
gotcha. thanks!
Posted: Tue Oct 25, 2005 3:57 pm
by RobertGonzalez
kristolklp wrote:gotcha. thanks!
Just to clarify, there are two parts to your question. One that involves the submission of a form based on a clicke vent raised when a checkbox is checked (this is a client-side code question - Javascript). The other is what happens after the form is submitted (a server-side code question - PHP). I do not want to step on Feyd's toes with my previous answer.
The form submission can be handled in a number of ways, even using a text link to post back to the script. The actual processing of the data that was sent by the form being submitted is what needs to be handled on the server.