Welcome to WebmasterWorld Guest from 54.211.17.91

Forum Moderators: incrediBILL

Message Too Old, No Replies

Self updating form

   
7:09 pm on Jun 1, 2012 (gmt 0)

5+ Year Member



Guys, I am a newb, so please forgive my newb question.
I am trying to build a simple webpage that updates itself with text. something like;

Page1 Form txt box and submit button
on submit
Page1 "New entered txt" and Form txt box with submit button

or is this not simple?

ideally, there will be many txt box's for name, date, ect...
5:43 pm on Jun 4, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Something like this . . . not a working code but gives you an idea.

<?php
$title = (isset($_POST['title']))?$_POST['title']:'Submit to Test';
$mytext = (isset($_POST['mytext']))?'<p>' . $_POST['mytext'] . '</p>':null;
<?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><?php echo $pagetitle; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<?php echo $mytext; ?>
<form method="post" action="thisscript.php">
<p><label for="title"> Enter a title:</label> <input type="text" name="title" id="title" value=""><p>
<p><label for="mytext"> Enter some text:</label> <textarea name="mytext" id="mytext" value=""><p>
</body>
</html>

Make sure this file is named "thissscript.php" or change the form action - it posts to itself.
6:13 pm on Jun 4, 2012 (gmt 0)

5+ Year Member



Is there a way to do this in html? What are my options if I dont have PHP or Perl. What if I had it update a second page, and not itself?
9:55 pm on Jun 4, 2012 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Sorry, there's no way to do that with HTML alone. That's why the various scripting languages are so powerful and valuable.
4:15 pm on Jun 5, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What server would you have that doesn't have both PHP and Perl? If it's an MS server, you can do this in .asp/.net.

A Javascript solution **could** work but then it's dependent on Javascript (disabled/not present = won't work.)


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Me</title>
<style type="text/css">
#mydiv { display:none; }
</style>
</head>
<body>
<h1 id="mainhead">Test Me</h1>
<div id="mydiv"></div>
<form method="post" id="myform" action="thispage.html">
<p><label for="title"> Enter a title:</label>
<input type="text" name="title" id="title" value=""></p>
<p><label for="mytext"> Enter some text:</label>
<textarea name="mytext" id="mytext" cols="12" rows="6"></textarea></p>
<p><input type="submit" value="Update"></p>
</form>
<script type="text/javascript">
//
window.onload=function() {
frm = document.getElementById('myform');
if (frm) { frm.onsubmit=function() { return writeMyStuff(); } }
};
//
function writeMyStuff() {
var hd = document.getElementById('mainhead');
var div = document.getElementById('mydiv');
var ttl = document.getElementById('title');
var txt = document.getElementById('mytext');
if (hd && div && ttl && txt) {
hd.innerHTML=ttl.value;
div.innerHTML = txt.value;
div.style.display='block';
}
return false;
}
</script>
</body>
</html>


That one is copy and paste tested code. :-)
2:44 pm on Jun 6, 2012 (gmt 0)



Most browsers support javascript unless the user has disabled it. The advantage of using javascript in this case is the ability to set cookies on the client. This allows you to populate the form with text that is customized for each user. I am guessing from your first post that this is what you want to do. Hope this helps.
8:01 pm on Jun 7, 2012 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Most browsers support javascript unless the user has disabled it. The advantage of using javascript in this case is the ability to set cookies on the client. This allows you to populate the form with text that is customized for each user. I am guessing from your first post that this is what you want to do. Hope this helps.


The problem with storing personal information in cookies is the need for informed consent in the EU. I would personally not recommend that route.

Server side scripting (Perl/PHP/ASP/.Net) is the way to go.
11:16 pm on Jun 7, 2012 (gmt 0)



Really, it depends on what you are trying to do. If you are planning to keep a database of your visitors' information, or if you want to populate data fields with specific information based on the input in other fields (e.g. populate city and state based on zipcode), then php/MySQL is surely the way to go.

If you are just providing pre-populated fields for returning visitors' convenience, it is simple enough to add a check box or radio button; ask if they would like their information saved, and point out that cookies must be enabled. Voila!
12:01 pm on Jun 11, 2012 (gmt 0)

WebmasterWorld Senior Member piatkow is a WebmasterWorld Top Contributor of All Time 5+ Year Member




What server would you have that doesn't have both PHP and Perl? If it's an MS server, you can do this in .asp/.net.

Some cut price hosting services don't provide support for server side languages.
11:40 pm on Jun 15, 2012 (gmt 0)

5+ Year Member



Hello again all, I have had a chance to grind this over with my supervisor, and have agreed that I can do it, but I have to use ASP and powershell or batch. Front page is my preference (Dont laugh), so any thoughts?
2:48 pm on Jun 16, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



See post # 4461308 and convert that to ASP, it should be a fairly simple model exercise for digging into .ASP/.NET. :-) Lots of tutorials out there to get you started.