/    Sign up×
Community /Pin to ProfileBookmark

Set a variable when button is clicked

Can anyone help me to write the code in java script. I am new to it.

I have the save button. When Save button is clicked which I presently configured like “<INPUT TYPE=button VALUE=”Save” ONCLICK=”savemethod()”>

I need to write the code so that when the save button is clicked, I need to set the form variable in savemethod() so that I can use that variable later in the code. After it sets the variable to something(either integer or true), I will write something like this:

If saveformvariable = true/1
then write to database (i mean upadte to database)
else Don’t update.

How can I set the Form variable when the button is clicked. Can soemone help me out plzzzzzzzzz…..It is a bit urgent…..Thanks a lot in advance.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@omnicityJul 06.2010 — Do you have any back-end (server-side) language, or is this just pure HTML ?
Copy linkTweet thisAlerts:
@pinky14authorJul 06.2010 — It has server side code. It is classic asp page. I had to implement the save button in it. Before it was a form data entry and submit button. Now I have to implement the save button. I have written the update statement in the code.

Now when clicked on saev button, it saves the data to database. But once you logged out and log back in, the data in the database is getting refreshed and saved as null. I am trying to implement like this:

When button is clicked, if we can set some form variable to a constant value in the javascript, it sets the value after clicking the save button. Before update statement, I can write check for the the value and if it is true, it updates or else it doesn't update.

Similarly, when the page is redirect from previous page,if it can set a value for another variable here then I can use that condition as well.

Hope I explained it correctly.

Thanks for Replying me and helping me out.
Copy linkTweet thisAlerts:
@pinky14authorJul 06.2010 — FORM :

<INPUT TYPE=button Name="savebutton" VALUE="Save" ONCLICK="savemethod()">


METHOD:

function savemethod()

{

savevar = evalform.savebutton.value;

var variable = 1

document.evalform.method = "post";

document.evalform.submit();

}


IN THE CODE:

If variable = 1 then

first_Name = request.form("First_Name")

Update statement - updates the database row.

ENd IF
Copy linkTweet thisAlerts:
@omnicityJul 07.2010 — Maybe I am mis-understanding, but would it not make more sense to ensure that the data in the page gets updated FROM the database every time the page is refreshed?

I am not an expert on ASP, but it rather sounds like you have that side of things a little bit wrong.
×

Success!

Help @pinky14 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...