tags:

views:

197

answers:

6

  <html>
  <head>
  <title>txt with js eff</title>
  </head>
   <body>

  <script type = "text/javascript">

  function transfer(which) {

  document.getElementById("temp_name").value = which;

  }

  </script>



  <form action="" method="post" name="frm1">

  <label> In put 1 </label><input type="text" name="username" id = "username" onkeyup = "transfer(this.value)"><br/><br/>

  <label> In put 2 </label><input type="text" name="temp_name" id = "temp_name">

  </form>

  </body>
  </html>

Dear Folks:

I need to do this by using php:

I need to pass the value to "In put 2" from "In put 1" when the user focuses his cursor to next field. I can do it very easily with js but I need to this with PHP.

If have any solution for that please let me know.

+13  A: 

You don't do this type of stuff with PHP, you do it with Javascript. PHP only runs on the server. You would have to post this page back to the server, have PHP write a block of javascript that causes a particular field to be focused once the page is loaded, then spit this back out for the user. In short, even if you worked out a way to do it with PHP, you'd end up doing it with Javascript still.

Jonathan Sampson
+2  A: 

Jonathan is right, you don't do that in PHP.

However, you have your code in Quotes, which leads me to believe that this code is in a string and you are presenting it to the user, in which case, there wouldn't be a value in either of the input boxes at execution time. What is the applicaion?

Senica Gonzalez
@Senica: I hope you don't mind but I added a link to your reference just in case the proximity between our posts increases.
Jonathan Sampson
@Jonathan, nope not at all.
Senica Gonzalez
+6  A: 

PHP is a server side language so it's job is just to generate the document that your browser will render. So once that document is created, there's no changing it. It's up to client side languages such as javascript to do so. The mouseover you are describing is definitely a job for something client-side.

You can request a page from the server with the new value but I don't think that's what you want to do.

jcmoney
A: 

the user is either "doing" something or the user is "asking" for something. If the user is just "doing" something, then it is all happening in the browser, like reading, typing and so on. The user asks for something by clicking a link or pressing a button. the program that responds to the user asking for something is written in php and php runs in the server. the program that responds to the user doing something is written in javascript and runs in the browser.

kinjal
A: 

The question is, "why do you want to do that in PHP?" :S

feragusper
A: 

maybe you want to save the values. just call the submit method after you make the changes in javascript, and then save it on the database or in session or whatever. Or maybe you can make an ajax request to avoid the page reload but really its hard to know what you are trying to achieve or understand.

useless