Google Answers Logo
View Question
 
Q: Browser (javascript) writing to server (like gmail's stars) ( No Answer,   2 Comments )
Question  
Subject: Browser (javascript) writing to server (like gmail's stars)
Category: Computers > Programming
Asked by: lampware-ga
List Price: $10.00
Posted: 23 Aug 2004 13:17 PDT
Expires: 13 Sep 2004 10:08 PDT
Question ID: 391498
I have hundreds of record per day in a web page application.  I want
to be able to click on a record and have the database updated realtime
for that record.  What gmail does with it's stars is very similar to
what I want.  I was thinking of just using a checkbox with each
record.  Then when the onclick event occurs I would have javascript
either post the record information (key & checked/unchecked) to a URL
or socket.  I can write the server side application to handle the
database update.  I just do not know how to do this client side piece.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Browser (javascript) writing to server (like gmail's stars)
From: pugio-ga on 23 Aug 2004 17:59 PDT
 
Well, I'm on a Mac/Unix box so I can't test out a couple of possible
solutions I've found. Basically, microsoft has some ActiveX plugins
that are pretty easy to use to write to a file. Do a search for
javascript write file.

Another method is to create a Java Applet on your page that has
capabilities to write to your database - the javascript can then call
the java applet easily.

And finally - the solution I cooked up using on JavaScript is:

First - let's assume the path to the script is:
http://www.yoursite.com/cgi-bin/yourscript.pl

The script can take two arguements:
http://www.yoursite.com/cgi-bin/yourscript.pl?key=something&value=something

The page containing this script will actually be a page containing two
frames. (Now before you go and start screaming about the use of frames
- this method is fairly painless.)

One frame will be the frame displaying all of the checkboxes
(mainFrame) while the other will be a hidden frame that has absolutely
no bearing on the look/function/appearance of your page.

When a checkbox is clicked, it calls a JavaScript function - passing
it's name (which key it represents) and its value (on or off). The
JavaScript function then tells the hidden frame to go to the URL:
http://www.yoursite.com/cgi-bin/yourscript.pl?key=THEKEY&value=ON/OFF

Your script will then take these values and update the database accordingly.

Code is as follows:

Page containing the frames:
---------------------------------------
<html>
<head>
<title>Update Database</title>
</head>
<body>
<frameset cols="0,*" frameborder="NO" border="0" framespacing="0">
  <frame src="http://www.yoursite.com/hiddenFrame.html" scrolling="NO" noresize>
  <frame src="http://www.yoursite.com/theRealFrame" name="mainFrame">
</frameset>

</body>
</html>
---------------------------------------


The Hidden Frame Page:
---------------------------------------
<html>
<body>
</body>
</html>
---------------------------------------


The Real Page:
---------------------------------------

<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript">
function UpdateDatabase(TheKey, TheStatus)
{
	URL = 'http://www.yoursite.com/cgi-bin/yourscript.pl?key=' + TheKey +
'&value=' + TheStatus;
	alert(URL);
	parent.hiddenFrame.location.href = URL;

}

</script>
</head>

<body>
<form name="form1" method="post" action="">
  <p>
    <input name="key1" type="checkbox" id="key1" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)">
    </p>
  <p>
    <input name="key2" type="checkbox" id="key2" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)">
  </p>
  <p>
    <input name="key3" type="checkbox" id="key3" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)">
  </p>
  <p>
    <input name="key4" type="checkbox" id="key4" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)">
  </p>
  <p>
    <input name="key5" type="checkbox" id="key5" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)">
  </p>
</form>
</body>
</html>

-----------------------------------------------------------------

That should get you started. I've already thought of a couple of other
issues - like maybe setting the status of each check box when the page
loads, but I don't know how much you need to know. Try creating this
page with a script and adding the "checked" keyword to the end of any
checkbox tagged that is checked.
Subject: Re: Browser (javascript) writing to server (like gmail's stars)
From: raistlinmajere-ga on 10 Sep 2004 01:06 PDT
 
Instead of using frames you could use layers so you have just to
insert some code on your page.
Be sure to protect the server side script so it can be accessed only
by your script. For example you could restrict IPs and use a password
as a third parameter.

---- YOUR PAGE ----------
<html>
<body>
<form name="form1" method="post" action="">
  <p><input name="key1" type="checkbox" id="key1" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)"></p>
  <p><input name="key2" type="checkbox" id="key2" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)"></p>
  <p><input name="key3" type="checkbox" id="key3" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)"></p>
  <p><input name="key4" type="checkbox" id="key4" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)"></p>
  <p><input name="key5" type="checkbox" id="key5" value="checkbox"
onClick="UpdateDatabase(this.name, this.status)"></p>
</form>
</body>
</html>
-------------------------

---- CODE TO INSERT -----

<script language="JavaScript">
function UpdateDatabase(TheKey, TheStatus) {
	var URL = 'http://www.yoursite.com/cgi-bin/yourscript.pl?key=' +
TheKey + '&value=' + TheStatus;
	//if you use PHP -> var URL =
'http://www.yoursite.com/admin/updatedb.php?key=' + TheKey + '&value='
+ TheStatus;

	parent.db_frame.location.href = URL;

}

</script>

<iframe id="db_frame" name="db_frame" src="javascript:" scrolling="no"
border="0" style="margin:0;padding:0;position:absolute;visibility:hidden;z-index:98;background-color:#ffffff;border:0
 none #ffffff;overflow:hidden;"></iframe>

-------------------------

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy