www.webdeveloper.com
Results 1 to 5 of 5

Thread: Set a variable when button is clicked

  1. #1
    Join Date
    Apr 2010
    Posts
    11

    Question 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.

  2. #2
    Join Date
    Jan 2005
    Posts
    349
    Do you have any back-end (server-side) language, or is this just pure HTML ?

  3. #3
    Join Date
    Apr 2010
    Posts
    11
    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.

  4. #4
    Join Date
    Apr 2010
    Posts
    11
    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

  5. #5
    Join Date
    Jan 2005
    Posts
    349
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles