0

i wanna enter a value passed by javascript function to the database. is there a way to do that? thanks.

var eng = 0;

var nothome = 0;

var nointerest = 0;
var callback = 0;
var booked = 0;
function myFunction(i,txt, elemid){
var plural;
if (i != 1) plural = "s.";
else plural = ".";
document.getElementById(elemid).innerHTML = txt + i + " time" + plural;
alert(txt + i + " time" + plural);
}

<button onclick="eng += 1; myFunction(eng,'Engaged: ','Engaged');">Engaged</button><span id="Engaged"></span>

                                    <button onclick="nothome += 1; myFunction(nothome,'Not Home: ','nothome');">Not Home</button><div id="nothome"></div>
                                    <button onclick="nointerest += 1; myFunction(nointerest,'No Interest: ','nointerest');">No Interest</button><div id="nointerest"></div>

                                    <button onclick="callback += 1; myFunction(callback,'Call Back: ','callback');">Call Back</button><div id="callback"></div>

                                    <button onclick="booked += 1; myFunction(booked,'Booked: ','booked');">Booked</button><div id="booked"></div>

i wanna insert the value of engaged, booked etc to the database. is there a way to do that? thanks.

what im trying to do here is when i click a button, the corresponding value increments by 1. and then i need to insert this value in the database. if not this way, is there any other way to do this??

Edited by Reverend Jim: Fixed formatting

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

you must use form tag in between, then define one hidden input. When user submits the form, set hidden input using your myfunction, and then process the form(insert the submited hidden value) in the form action page.

Edited by urtrivedi: n/a

0

You can also use AJAX for that. Than the database is altered in the background, without the need to refresh the page.

0

As twiss says, you can use Ajax for that. Only php (server-side) will insert to DB. SO you can either do it via normal form submit or via ajax.

Ajax pretty much just hijacks the submit procedure (or even a button click etc), does some jiggery pokery with js and php, so you don't need to refresh.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.