homepage Welcome to WebmasterWorld Guest from 54.161.181.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Self updating form
blankmonkey




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

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

 

rocknbil




msg:4461308
 5:43 pm on Jun 4, 2012 (gmt 0)

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.

blankmonkey




msg:4461326
 6:13 pm on Jun 4, 2012 (gmt 0)

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?

tedster




msg:4461383
 9:55 pm on Jun 4, 2012 (gmt 0)

Sorry, there's no way to do that with HTML alone. That's why the various scripting languages are so powerful and valuable.

rocknbil




msg:4461684
 4:15 pm on Jun 5, 2012 (gmt 0)

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. :-)

Tzakuk




msg:4462069
 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.

DrDoc




msg:4462627
 8:01 pm on Jun 7, 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.


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.

Tzakuk




msg:4462722
 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!

piatkow




msg:4463880
 12:01 pm on Jun 11, 2012 (gmt 0)


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.

blankmonkey




msg:4466093
 11:40 pm on Jun 15, 2012 (gmt 0)

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?

rocknbil




msg:4466252
 2:48 pm on Jun 16, 2012 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved