/    Sign up×
Community /Pin to ProfileBookmark

wrtie to active page

Hi

I know this is possble, I have been doing some seaching with no luck.

I have a webapge with a form and when the user clicks the enter button I want text to appear on the the page.

( I know how to do this buy setting the form action to say”page.php” and code that page to transfer the values.

Not shure how to do it so that it adds to the same page

any thoughts

thank you

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@SheldonApr 11.2006 — you mean with out refresting the page?
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — yes,

you know how on some pages when you use a form and click enter it writes to the page
Copy linkTweet thisAlerts:
@SheldonApr 11.2006 — or[code=php]
<?php
//page.php

if(isset($_GET['pagecomments'])){
echo("<b>" . $_GET['pagecomments'] . "</b>");
}else{
?>
<form action="page.php" action="get">
<input type="text" name="pagecomments" style="width: 200px;">
<input type="submit" value="submit">
</form>
<?php
}
?>
[/code]
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — Thank you for the reply not sure that I'm following

based on the below I want a message to appear at the top of the page


"based on the value of "interestRate" the interest rate spread is " ratespread"

hope this makes sense

here is some of my code

some variables


<i>
</i>var ratespread = (interestRate - (remainingTermInterestRate /100) - bonus);
var IRD = ratespread * mortgageBalance * diffMonths


some form code

<i>
</i>
&lt;label for="interestRate"&gt;
Mortgage Interest Rate:
&lt;input id="interestRate" name="interestRate" type="text" value="" /&gt;
&lt;/label&gt;

&lt;label for="interestRate"&gt;
Rate Discount:
&lt;input id="bonus" name="bonus" type="text" value="" /&gt;
&lt;/label&gt;
Copy linkTweet thisAlerts:
@SheldonApr 11.2006 — try this
[code=php]
<?php
//page.php

if(isset($_GET['pagecomments'])){
echo("<b>based on the value of " . $_GET['interestrate'] . " the interest rate spread is " . $_GET['bonus'] . "</b>");

}else{
?>
<form action="page.php" action="get">


<label for="interestRate">
Mortgage Interest Rate:
<input id="interestRate" name="interestRate" type="text" value="" />
</label>

<label for="interestRate">
Rate Discount:
<input id="bonus" name="bonus" type="text" value="" />
</label>

<input type="submit" value="submit">
</form>
<?php
}
?> [/code]

If its not what you want im sure it is a good start you to get going with it.
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — thankyou very much. I'm getting it figured out


last questions

does the ['pagecomments'] refer to anything special on the page

Also not all values will come from form fields, some will be calculated variables.
Copy linkTweet thisAlerts:
@welshApr 11.2006 — as to the pagecomments not sure, but for the calculated variables after the:

if(isset($_GET['pagecomments'])){

just add what ever variables needed, any calculations then echo the rest.
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — I have still been unable to get this to work, I'm starting to feel stupid. When I use the form and click the submit button nothing happens.


---
My code is setup as a javascript function, at the end of the code I placed the PHP code which is just above the form. My page is styled using CSS.

My goal is that the text strying will be placed above the form(note: form will need to be pushed down)

any advice
Copy linkTweet thisAlerts:
@bokehApr 11.2006 — Writing to the same page is simply a matter of appending a node. Although it is not PHP (it's Javascript) here's a quick demo.[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function appendInputToBody(input_object)
{
newParagraph = document.createElement('p')
newParagraph.appendChild(document.createTextNode(input_object.getElementsByTagName('input')[0].value))
document.getElementsByTagName('body')[0].appendChild(newParagraph)
/* Clear the text box */
input_object.getElementsByTagName('input')[0].value = ''
return false;
}
</script>

<title>Append</title>

</head>

<body>

<form action="" method="POST" onsubmit="return appendInputToBody(this)">
<p><input type="text" name="whatever"></p>
<p><input type="submit" value="Append node"></p>
</form>

</body>

</html>[/code]
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — Hi

I did not want to post all my code because its quite long. I have not been doing a vary good job at explaining myself.

so here it is

[code=html]
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
<META NAME="keywords" CONTENT="">
<META NAME="description" CONTENT="">
<META NAME="ROBOTS" CONTENT="ALL">

<title>Mortgage Penalty Calculator</title>
<script src="../javascript/lendingrates.js" type="text/javascript"></script>
<script type="text/javascript">


function compute(mortgagePenalty){

var mortgageBalance = parseInt(document.mortgagepenalty.mortgageBalance.value);
var termStartDate = document.mortgagepenalty.termStartDate.value;
var termLength = document.mortgagepenalty.termLength.value;
var bonus = (document.mortgagepenalty.bonus.value)/100;
var interestRate = parseInt(document.mortgagepenalty.interestRate.value)/100;
//var remainingTermInterestRate = parseInt(document.mortgagepenalty.remainingTermRate.value)/100;
var cashbackdollars = parseInt(document.mortgagepenalty.cashbackdollars.value);

//---- Three Months Interest ---------------------

var threeMonthsInterest = Math.round(100*[(mortgageBalance * interestRate)/4]/100);


var usrDate = new Date(termStartDate);
var curDate = new Date();
var usrYear, usrMonth = usrDate.getMonth()+1;
var curYear, curMonth = curDate.getMonth()+1;
if((usrYear=usrDate.getFullYear()) < (curYear=curDate.getFullYear())){
curMonth += (curYear - usrYear) * 12;
}
var diffMonths = curMonth - usrMonth;
if(usrDate.getDate() > curDate.getDate()) diffMonths--;


//---------Interest Rate Differential------------
var ratespread = (interestRate - (remainingTermInterestRate /100) - bonus);
var IRD = ratespread * mortgageBalance * diffMonths

var penalty;
if(IRD > threeMonthsInterest)
penalty = IRD
else if (IRD < threeMonthsInterest)
penalty = threeMonthsInterest;

//-------- cash back repayment-----------

var cashbackrepayment = cashbackdollars * ([termLength - diffMonths]/termLength)

}

//----------------------------------------

fN = "mortgagepenalty"; //form name
eN = "yesNo"; //radio name
vV = 0; //visible value (for radio)
tN = "cashbackdollars"; //toggle input name
lI = "cashback"; //label id
function togInp() {
var val = document.forms[fN].elements[eN][vV].checked;
val = (val==true) ? "yes" : "no";
if (val=="yes") {
document.forms[fN].elements[tN].style.visibility = "visible";
document.getElementById(lI).style.visibility = "visible";
} else if (val=="no") {
document.forms[fN].elements[tN].style.visibility = "hidden";
document.getElementById(lI).style.visibility = "hidden";
}
}

</script>


<style type="text/css" media="all">
@import "../css/main.css";
@import "../css/mortgagepenaltycalculator.css";

</style>

</head>
<?php include("../header.html"); ?>
<body>
<div id="outer">
<div id="sub">
<div id="center">
[code=php]
<?php
//mortgagepenaltycalculator.php

if(isset($_GET['pagecomments'])){
echo("<b>based on the value of " . $_GET['interestRate'] . " the interest rate spread is " . $_GET['bonus'] . "</b>");

}else{
?>
[/code]

<form name="mortgagepenalty" id="horizontalForm" action="mortgagepenaltycalculator.php" action="get">

<div id="mortgagepenalty">

<fieldset>

<legend>Mortgage Penalty Calculator</legend>

<label for="mortgageBalance">

Mortgage Balance:

<input id="mortgageBalance" name="mortgageBalance" type="text" value="" />

</label>

<label for="termStartDate">

Term Start Date:

<input id="termStartDate" name="termStartDate" type="text" value="" />

</label>

<label class="termLengh" for="termLength">

Term Length:

<select id="termLength" name="termLength">

<option value="0">choose</option>

<option value="12">1 Year</option>

<option value="24">2 Year</option>

<option value="36">3 year</option>

<option value="48">4 Year</option>

<option value="60">5 Year</option>

<option value="72">7 Year</option>

<option value="120">10 Year</option>

</select>

</label>

<label for="interestRate">

Mortgage Interest Rate:

<input id="interestRate" name="interestRate" type="text" value="" />

</label>

<label for="interestRate">

Rate Discount:

<input id="bonus" name="bonus" type="text" value="" />

</label>

<label class="cashback" for="cashback">

Was cash given back?

</label>

<label class="radio">

Yes

<input class="radio" id="radio" type="radio" name="yesNo" value="yes" onclick="togInp()">

</label>

<label class="radio">

No

<input class="radio" id="radio" type="radio" name="yesNo" value="no" onclick="togInp()" checked>

</label>

<label class="cashback" for="cashbackdollars" style="visibility: hidden" id="cashback">

Cash Back Amount:

<input name="cashbackdollars" type="text" value="" style="visibility: hidden">

</label>

<input id="submit" type="submit" value="Calculate" onclick="compute(this.form)">

<input id="reset" type="reset" value="Reset">

</fieldset>

</div>

</form>

<?php

}

?>

</div>

<div id="left">

<?php include("../menubar.html"); ?>

</div>

</div>


<div id="footer">
<p>Copyright &copy; TomorrowNextweek.com</p>
</div>
</div>



</body>

</html>

[/code]
Copy linkTweet thisAlerts:
@bokehApr 11.2006 — I did not want to post all my code because its quite long. I have not been doing a vary good job at explaining myself.[/QUOTE]Is there a question or problem hidden in this post somewhere. Read [URL=https://webdeveloper.com/forum/showthread.php?t=64280]help us to help you[/URL] and then try to reformat your question into something understandable.
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — The problem I'm having is its not writting the text to the page, the php script appears to be doing nothing.

when I click the submit button the page flashes but none of the data is written to the to the page.
Copy linkTweet thisAlerts:
@bokehApr 11.2006 — submit button the page flashes but none of the data is written to the to the page.[/QUOTE]Is it supposed to do something in javascript? Or in the subsequent PHP page. If the Javascript is to do anything at all it will need an event handler.
Copy linkTweet thisAlerts:
@SheldonApr 11.2006 — also i hope that you arnt trying to run the page with the VB Tags [ php ] in your page as it looks like on your post above

and i wrote something wrong, you neeto to change this line:
[code=php]if(isset($_GET['pagecomments'])){ [/code]
to [code=php]if(isset($_GET['interestrate'])){ [/code]
Copy linkTweet thisAlerts:
@kprocauthorApr 11.2006 — thank you for the reply, the change you recomended worked.

I ran into a little snage. I want the value or avariable declared and set in my javascript to be used in the text

I placed the variable but it did nothing. Only values from the form will pull through
Copy linkTweet thisAlerts:
@SheldonApr 12.2006 — search parsing javascript in php on this forum and it will help you
Copy linkTweet thisAlerts:
@bokehApr 12.2006 — I want the value or avariable declared and set in my javascript to be used in the text

I placed the variable but it did nothing.[/QUOTE]
Did you read my post #14? You do not have an event handler. That is like trying to fire a gun with no trigger.
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...