Jump to content

JavaScript to PHP


craigafer

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/213218-javascript-to-php/
Share on other sites

Hi there,

Javascript is a client side scripting language so there is no interaction between the client ( browser ) and the server. However, PHP is a server side scripting language so your browser send a request to the server, the server evaluate and process your request and the send the response to the browser again. In PHP, you can get the value of your input field by using the super global array $_POST and in your case, you can access the variable in your PHP script using $_POST['one'] (i.e. by the name of the field and not the id). 

Link to comment
https://forums.phpfreaks.com/topic/213218-javascript-to-php/#findComment-1110254
Share on other sites

PHP and javascript are not interchangeable. PHP generates pages. Javascript runs after the page is loaded.

 

how can i do this in php?

$_POST["txt1"]="Hello World" "?"

 

You have to echo the HTML for the txt1 with hello world in it.

 

<?php
$text = "Hello world";
?>
<input type="text" value="<?php echo $text ?>"/>

Link to comment
https://forums.phpfreaks.com/topic/213218-javascript-to-php/#findComment-1110342
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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