Jump to content

craigafer

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

craigafer's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thnx for the help done with it is there a built in mdas function in php?
  2. well to be honest i cant buy the book yet :'( im a working student, and got many books to buy but i would appreciate it if my last question will be answered, since the submission of this is on thursday
  3. last 1 and it will be marked as solved!! i will buy the book as soon as possible <?php session_start(); $buttonVal = 0; $compute = 0; $newnum = 0; $display =0; $text = 0; global $buttonVal, $compute, $newnum, $display, $text; if(isset($_POST["btn1"])) { $display=$_POST["btn1"]; setNum($display); } function setNum($text) { if($newnum==0) { $buttonVal = $text; $newnum=1; } else { $buttonVal = $buttonVal . $text; } } ?> <!doctype html> <html lang="en-us"> <head> <title>Example</title> </head> <body> <form action="omg.php" method="post"> Display: <input name="display" type="text" readonly="readonly" value="<?php echo $buttonVal; ?>" /><br> <input type="submit" value="1" name="btn1" id="btn1" /> <input type="submit" value="2" name="btn1" id="btn1" /> <input type="submit" value="3" name="btn1" id="btn1" /> <input type="submit" value="4" name="btn1" id="btn1" /> <input type="submit" value="5" name="btn1" id="btn1" /><br> <input type="submit" value="6" name="btn1" id="btn1" /> <input type="submit" value="7" name="btn1" id="btn1" /> <input type="submit" value="8" name="btn1" id="btn1" /> <input type="submit" value="9" name="btn1" id="btn1" /> <input type="submit" value="0" name="btn1" id="btn1" /><br> <input type="submit" value="+" name="btn2" id="btn2" /> <input type="submit" value="-" name="btn2" id="btn2" /> <input type="submit" value="*" name="btn2" id="btn2" /> <input type="submit" value="/" name="btn2" id="btn2" /> <input type="submit" value="=" name="btn2" id="btn2" /> </form> </body> </html> im done with the displayin, but whats the prob here nao? it doesnt display the $buttonVal but when you echo it, it echoes the right value
  4. You don't have a button named submit in your form now. That means your PHP code at the top will never work. The superglobal $_POST array works by using the names of your HTML form inputs. $_POST['submit'] maps to <input type="submit" name="submit" value="submit" />, just as $_POST['username'] would map to something like <input type="text" name="username" />. Take note of the parts that are bold. Have you bought that book yet? You'll learn a lot more with a good book than reading free tutorials of questionable quality and throwing a bunch of code at the wall to see what actually sticks. i cant find the book you were saying here i got your point so if i renamed if(isset($_POST['submit'])) to if(isset($_POST['btn1'])) will it display the value of btn1?
  5. sorry for the super late reply i became busy so i kinda tryin to edit what NightSlyr posted but again i failed <?php if(isset($_POST['submit'])) { $buttonVal = $_POST['btn1']; } ?> <!doctype html> <html lang="en-us"> <head> <title>Example</title> </head> <body> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> Display: <input name="display" type="text" value="<?php if(isset($buttonVal)){ echo $buttonVal; } ?>" /> <input type="submit" value="1" name="btn1" id="btn1" /> </form> </body> </html> how can i display the value of the button everytime i clicked it?
  6. <?php session_start(); $display = 0; global $display; function getvalue($num) { if($num==1) { $display.="1"; } else { $display.="2"; }; return($display); } ?> <html> <head> <title>Home</title> </head> <body> <form action="calcu.php" method="POST"> <input type="text" name="display" id="display" readonly="readonly" value="<?php echo $display?>"> <input type="submit" name="btn" value="1"> <input type="submit" name="btn" value="2"> </form> </body> </html> edited it sorry for being so noob -__- got no reference to study
  7. my problem is i want to display on the text box, the value of the buttons that i pressed
  8. alright i will look for that book but can you please have a solution for my problem?
  9. theres a couple of php books here what should i get? thats the only problem i have passing values to functions and displaying it
  10. tried what you guys said but it doesnt work <?php session_start(); $display = 0; global $display; function getvalue($num) { if($num==1) { $display.="1"; } else { $display.="2"; }; return($display); } ?> <html> <head> <title>Home</title> </head> <body> <form action="calcu.php" method="POST"> <input type="text" name="display" id="display" readonly="readonly" value="<?php echo $display?>"> <input type="submit" name="btn" value="1" onclick="<?php getvalue(1);?>"> <input type="submit" name="btn" value="2" onclick="<?php getvalue(2);?>"> </form> </body> </html>
  11. That is not going to call your PHP function. The web browser is going to assume that getvalue() call is a javascript function and throw an error saying getvalue() is not defined. To call your PHP function from there you need to enclose the function call inside normal <?php ?> tags. That said, if you used the correct syntax there it would not make sense to be inserting an <input> tag inside an onclick attribute. is this correct now? i've tried what you've said here is the code: its a simple display of 1 and 2 <?php session_start(); $display = 0; global $display; function getvalue($num) { if($num==1) { $display.="1"; } else { $display.="2"; }; } ?> <html> <head> <title>Home</title> </head> <body> <form action="calcu.php" method="POST"> <input type="text" name="display" id="display" readonly="readonly" value="<?php echo $display?>"> <input type="submit" name="btn" value="1" onclick="<?php getvalue(1)?>"> <input type="submit" name="btn" value="2" onclick="<?php getvalue(2)?>"> </form> </body> </html> but it doesnt display 1 or 2
  12. hi guys im back for more php questions hope you dont get annoyed <?php function getvalue($num) { echo "<input type='text' name='txt1' value='$num'>"; } ?> <html> <head> <title>Home</title> </head> <body> <form action="" method="POST"> <input type="text" name="txt1" id="txt1" value="0"> <input type="button" name="btn1" id="btn1" value="1" onclick="getvalue(1);"> <input type="button" name="btn2" id="btn2" value="2" onclick="getvalue(2);"> </form> </body> </html> here is my code my question is how can i pass the values at the php function? how can i display the passed value to the textbox txt1? is this code correct? echo "<input type='text' name='txt1' value='$num'>";
  13. thnx im gonna try it im currently resting for awhile
  14. so txt1 is a textfield document.getElementByID("txt1").value = "Hello World"; how can i do this in php? $_POST["txt1"]="Hello World" "?" i really dont know sorry if its wrong xD
  15. well i got more questions since i started at javascript and now im currently practicing php my question is whats the equivalent of this lines of codes to php language? document.getElementById("txt1").value <input type="button" name="one" id="one" value="1" onclick="javascript:getvalue(1);"\> == well what i mean is can i pass value to php functions every time i click it? just like calculators OT: can some1 help me translating my js calcu codes to php ones? document.getElementById("txt1").value this is my main problem i cant display the buttons i click
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.