Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,185 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,314 people online right now. Registration is fast and FREE... Join Now!




can javascript remember old values?

 
Reply to this topicStart new topic

can javascript remember old values?, want to use java to return html text inputs to default values initiall

adamgram
post 23 Sep, 2008 - 04:14 PM
Post #1


New D.I.C Head

*
Joined: 17 Sep, 2008
Posts: 7


My Contributions


Okay, so I have a PHP/MySQL based site and I'm trying to put together an 'edit your post' page. Basically everything the user previously put in pops up as an html form with disabled fields. Currently I have a Java script activated by a link to remove the 'disable' from an individual field if the user wants to edit it, but I also want to add a 'reset' link to return to the initial values if the user changes his/her mind about one field in the midst of filling out the form.

When the form first pops up, the initial html values are dictated by PHP. By clicking 'edit' they can alter these values, and what I want them to be able to click 'reset' and return to the initial values. However, since PHP is on the server and Java with the client, if I understand things correctly Java can't re-retrieve the PHP values as I did the first time around.

Instead I am curious to find a way with Java read the initial value, remember it, and later, if the user hits 'reset', send it back to the HTML. Below is a piece of my code. Basically I want to replace the "default" in the rest_name_rest function with whatever the output of <?php echo $row[rest_name]?> was when the page was first loaded. Thanks in advance for the help!!!

CODE

<html>
<head>

<script type="text/javascript">
function rest_name_enable(){
if (document.all || document.getElementById){
document.form_name.rest_name.disabled=false}}
</script>

<script type="text/javascript">
function rest_name_reset(){
if (document.all || document.getElementById){
if (document.form_name.rest_name.disabled==false)
{var r=confirm("This will delete whatever you just typed!!" + '\n' +
"Are you sure you want to reset the Restaurant Name?");
if (r==true)  {
document.form_name.rest_name.disabled=true
document.form_name.rest_name.value="default"}
else {}}
else {}}}

</script>
</head>
<body>

<form name="form_name">
<input name="rest_name" type="text" value="<?php echo $row[rest_name]?>" disabled="disabled">
<a href = "java script:rest_name_enable()">edit</a>
<a href = "java script:rest_name_reset()">reset</a><br>

</body>
</html>


Moved to JavaScript forum

This post has been edited by pbl: 23 Sep, 2008 - 04:46 PM
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 23 Sep, 2008 - 04:46 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,981



Thanked 78 times

Dream Kudos: 1175
My Contributions


This is the wrong forum, this is a javascript question, not a Java question.

Basically all you need to do is create a variable that holds the initial values, and if the user decides to revert the value it pulls the value from the variable and places it in the field.
User is offlineProfile CardPM

Go to the top of the page

adamgram
post 23 Sep, 2008 - 05:14 PM
Post #3


New D.I.C Head

*
Joined: 17 Sep, 2008
Posts: 7


My Contributions


QUOTE(BetaWar @ 23 Sep, 2008 - 05:46 PM) *


Basically all you need to do is create a variable that holds the initial values, and if the user decides to revert the value it pulls the value from the variable and places it in the field.


Yes, but how? I tried the obvious... putting

var def;
def=document.form_name.rest_name.value;

at various stages in the script, but nothing seemed to work...
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 23 Sep, 2008 - 05:36 PM
Post #4


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,981



Thanked 78 times

Dream Kudos: 1175
My Contributions


You are looking for something like this:

CODE
<script type="text/javascript">
function rest_name_enable(){
  if(document.all || document.getElementById){
    document.form_name.rest_name.disabled = false;
    document.form_name.rest_name.defVal = document.form_name.rest_name.value;
  }
}

function rest_name_reset(){
  if(document.all || document.getElementById){
    if(document.form_name.rest_name.disabled == false){
      var r = confirm("This will delete whatever you just typed!!\nAre you sure you want to reset the Restaurant Name?");
      if(r == true){
        document.form_name.rest_name.disabled = true;
        document.form_name.rest_name.value = document.form_name.rest_name.defVal;
      }
      else{
      }
    }
    else{
    }
  }
}

</script>

<form name="form_name">
<input name="rest_name" type="text" value="<?php echo $row[rest_name]?>" disabled="disabled">
<a href = "java script:rest_name_enable()">edit</a>
<a href = "java script:rest_name_reset()">reset</a><br>


I posted a snippet on something like this a while back:
http://www.dreamincode.net/code/snippet2326.htm

Hope that helps.
User is offlineProfile CardPM

Go to the top of the page

adamgram
post 23 Sep, 2008 - 05:47 PM
Post #5


New D.I.C Head

*
Joined: 17 Sep, 2008
Posts: 7


My Contributions


SWEET!! Thanks a lot man. I'm really new to all this and building this site as a way of learning... I read online tuts and whatnot but sometime specific questions are hard to track down. I really appreciate all the help I've got on these forums. Thanks again!

QUOTE(BetaWar @ 23 Sep, 2008 - 06:36 PM) *

You are looking for something like this:

CODE
<script type="text/javascript">
function rest_name_enable(){
  if(document.all || document.getElementById){
    document.form_name.rest_name.disabled = false;
    document.form_name.rest_name.defVal = document.form_name.rest_name.value;
  }
}

function rest_name_reset(){
  if(document.all || document.getElementById){
    if(document.form_name.rest_name.disabled == false){
      var r = confirm("This will delete whatever you just typed!!\nAre you sure you want to reset the Restaurant Name?");
      if(r == true){
        document.form_name.rest_name.disabled = true;
        document.form_name.rest_name.value = document.form_name.rest_name.defVal;
      }
      else{
      }
    }
    else{
    }
  }
}

</script>

<form name="form_name">
<input name="rest_name" type="text" value="<?php echo $row[rest_name]?>" disabled="disabled">
<a href = "java script:rest_name_enable()">edit</a>
<a href = "java script:rest_name_reset()">reset</a><br>


I posted a snippet on something like this a while back:
http://www.dreamincode.net/code/snippet2326.htm

Hope that helps.

User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 23 Sep, 2008 - 05:51 PM
Post #6


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,981



Thanked 78 times

Dream Kudos: 1175
My Contributions


No problem, happy to have helped out smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 04:14PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month