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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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