I'm sorry in advance if this is a really stupid question. Basically I have a Text box and a submit button, What I want to happen is:
I write things into the text box and then press the submit button, when the submit button is pressed it will echo the text from the text box underneath.
I know how to get the value of the text box into the echo, but how would I construct an if statement with the condition of
ButtonName == Pressed?
I tried:
Button.ButtonName == 1
But it doesn't seem to be working.
Not sure what you mean exactly, but a simple..
[cpp]
if($_POST['submit']){
//button pressed
echo $_POST['textfield'];
}
[/cpp]
..would do?
[editline]07:29PM[/editline]
Also, this should go in Web Programming, for future reference
PHP is serverside, you can't change the page with PHP, only make the page in the first place.
You need to use javascript.
[url]http://www.javaworld.com/jw-06-1996/jw-06-javascript.html[/url]
[url]http://www.w3schools.com/tags/tag_button.asp[/url]
look at the event attributes.
And next time, ask [url=http://www.facepunch.com/forumdisplay.php?f=353]here[/url] :)
[editline]07:32PM[/editline]
:ninja:
[c]<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">[/c]
For that it would be
[c]if ($_POST['Submit1])[/c]
Doesn't seem to be working.
I just need the condition for if the button is pressed
[editline]06:36PM[/editline]
and ok sorry :D
[QUOTE=deamer44;23940554][c]<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">[/c]
For that it would be
[c]if ($_POST['Submit1])[/c]
Doesn't seem to be working.
I just need the condition for if the button is pressed
[editline]06:36PM[/editline]
and ok sorry :D[/QUOTE]
That's because like I said PHP cannot change the page. Javascript is required for that.
[QUOTE=deamer44;23940554][c]<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">[/c]
For that it would be
[c]if ($_POST['Submit1])[/c]
Doesn't seem to be working.
I just need the condition for if the button is pressed
[editline]06:36PM[/editline]
and ok sorry :D[/QUOTE]
You can make the button, on hit, execute a javascript function. I forget how to do that...
<input type="submit" onClick="function();">
[code]
<script type="text/javascript>
<input type="button" name="submit" value="Submit" onClick="window.navigate('newpage.php')"></script>[/code]
would that work to go to a new page? Is that the correct way to insert javascript?
Im using XAMPP and it doesn't seem to like rendering javascript, with that script tag in nothing is shown.
[QUOTE=deamer44;23941077][code]
<script type="text/javascript>
<input type="button" name="submit" value="Submit" onClick="window.navigate('newpage.php')"></script>[/code]
would that work to go to a new page? Is that the correct way to insert javascript?
Im using XAMPP and it doesn't seem to like rendering javascript, with that script tag in nothing is shown.[/QUOTE]
You never said you wanted it to actually GO to a new page. It's entirely possible using PHP to have the text box info go to a new page when the button is pressed.
[editline]06:15PM[/editline]
[lua]
<html>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
[/lua]
Then in welcome.php:
[lua]
Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!
[/lua]
Sorry, you need to Log In to post a reply to this thread.