-2

I have a form with 2 textboxs. with js handling

<script type = "text/javascript">
function autofill(which) {
document.getElementById("text2").value = which;
}
</script>
<input type="text" name="text1" onblur="autofill(this.value)" />
<input type="text" name="text2" />

So According the above js, when user type some thing on text1 text box automatically update it to the text2 text box...

My question is how I handle this case by php..?

5
Contributors
18
Replies
19
Views
7 Years
Discussion Span
Last Post by Jerail
0

Do you mean $_POST['text1']=$_POST['text2']; ?

No i need it like auto filing... hera this is my complete code

<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="register">
<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>

try this code and you can see what is happening to "Input 2" while typing on "In put 1" I need to handle it by php...!
can you help me....?
If can Im so appreciate...

0

nothing happens with PHP until you do a submit.
JS is what you want for "real time" effects.
Once the page is rendered, PHP has already done what it is going to do.
Perhaps you want to echo the results back after submit?
I'm not clear as to what you are trying to accomplish.

0

Do you mean autofilling or autofiling (files)?? I assume you mean the former. You're transferring the contents of the first input box to the next 'as you type', correct? Code seems fine and dandy to me. Why on earth do you need pHp? You can't use pHp to do anything that js can't in this situation. If you're thinking of using Ajax - nope - js again. You're stuck with JS. Rule of thumb - if you want the PAGE to react to the user's actions - it's JS (or Ajax).

As mentioned, php is done, through, finito, caput, once it's sent to the client - the client just accepts html - it is not aware that it was produced by php. Well, pretty much anyway.

Edited by diafol: n/a

0

My question is how I handle this case by php..?

I received your pm and as ardav explained, php does not really have any involvement in this situation. Also I tested your script and it works like it should. So what is your script not doing as it does exactly what you describe you want it to do?

0

Im so appreciate and happy about your kindly replies... OK I need to pass "In put 1" value to "In put 2".. if u have any suggestions or code to do this plz make a note....

Thank you...
Umanda

Edited by umandajayo: n/a

0

Maybe something like this?
But it still requires a submit...

<?php
if(isset($_POST['submit'])) {
    $valueB = ' value="' . $_POST['valueA'] . '"';
}
?>
<html>
<body>
<input type="text" name="inputA" />
<input type="submit" name="submit" value="GO" />
<br /><br />
<input type="text" name="inputB"<?php echo $valueB; ?>>
</body>
</html>

Edited by Jerail: n/a

0

Do you mean autofilling or autofiling (files)?? I assume you mean the former. You're transferring the contents of the first input box to the next 'as you type', correct? Code seems fine and dandy to me. Why on earth do you need pHp? You can't use pHp to do anything that js can't in this situation. If you're thinking of using Ajax - nope - js again. You're stuck with JS. Rule of thumb - if you want the PAGE to react to the user's actions - it's JS (or Ajax).

As mentioned, php is done, through, finito, caput, once it's sent to the client - the client just accepts html - it is not aware that it was produced by php. Well, pretty much anyway.

You are correct..! I need transferring the contents of the first input box to the next when I Focus my curser to next input box(input box 2).. I need to do it by using pHp..if u have any sugection o code plz let me to know

Thank you

0

Maybe something like this?
But it still requires a submit...

<?php
if(isset($_POST['submit'])) {
    $valueB = ' value="' . $_POST['valueA'] . '"';
}
?>
<html>
<body>
<input type="text" name="inputA" />
<input type="submit" name="submit" value="GO" />
<br /><br />
<input type="text" name="inputB"<?php echo $valueB; ?>>
</body>
</html>

Thank your reply...did you test this code on your pc...? Ops...! I struggling...It is not working...I mane no any visible function to see.....

0

Thank your reply...did you test this code on your pc...? Ops...! I struggling...It is not working...I mane no any visible function to see.....

Your code have some errors..I found those and fixed....any way thank you for your consideration

<?php
   
      if(isset($_POST['submit'])) {
   
       	$valueB1 = ' value="' . $_POST['inputA'] . '"';
   		
		  }
		?>
<html>
<body>
<form action="" method="post">
<input type="text" name="inputA" />
<input type="submit" name="submit" value="GO" />
<br /><br />
<input type="text" name="inputB"<?php echo $valueB1; ?>/>
</form>
</body>
</html>
0

You are correct..! I need transferring the contents of the first input box to the next when I Focus my curser to next input box(input box 2).. I need to do it by using pHp..if u have any sugection o code plz let me to know

Thank you

The js code works fine for this - I really don't see why you need php. When on a 'static' page, the only way to get interactivity (e.g. change form widget values / html content / style attributes etc) is via JS. You can't do it via pHp alone. This can only be done via Ajax or similar technology, which depends on JS.
If you want a pure pHp solution, you'll have to submit the form every time you change focus - which unfortunately will, you guessed it, depend on JS.

As far as I can see, pure pHp will not be able to solve your problem.

0

The js code works fine for this - I really don't see why you need php. When on a 'static' page, the only way to get interactivity (e.g. change form widget values / html content / style attributes etc) is via JS. You can't do it via pHp alone. This can only be done via Ajax or similar technology, which depends on JS.
If you want a pure pHp solution, you'll have to submit the form every time you change focus - which unfortunately will, you guessed it, depend on JS.

As far as I can see, pure pHp will not be able to solve your problem.

Thanks ur post
I don't want to do it via php alone..Im ready to use ajax o smthing similer...But I cant use ONLY js for this..becoz Im nw developing a web site by using joomla..that is wy I try to do this with php... if u have any ajax solution or code block plz let me to knw..
Thanks...
Umanda

0

The point is uman - you CAN'T use php for this. The Ajax solution is so unnecessary that I shouldn't even have mentioned it. If you have to use js (and you HAVE TO), and you can run a script that only uses JS, for the life of me, I can't understand why you need to involve server-side scripting.

Scripts, as you probably know, can be placed in a script tag, an external file (referenced via script tag) or inline in a js attribute like onclick, onchange, onselect, onblur, onfocus etc etc etc. If this functionality is a "one-off" and you're getting into difficulty with external files or the head area because you're using Joomla! - make the code inline - it should work.

0

Thank you very much...I appreciate very much your help, but my Superior (our team leader) told me..."Please try to use server side scripting because some js may not support every browsers....?
can you tel me please..Is there any browser compatibility problem with my js code block..?

0

Thank you very much...I appreciate very much your help, but my Superior (our team leader) told me..."Please try to use server side scripting because some js may not support every browsers....?
can you tel me please..

Well php is only a preprocessor or more specifically a "hypertext preprocessor". Since php is a preprocessor it can only process the page before the page loads. So the only way you can make php validate this in addition to your javascript is with the following:

$_POST['field1']=$_POST['second_field'];

That will guarantee that both fields are the same.

Is there any browser compatibility problem with my js code block..?

This is not so much a compatibility issue but in any browser the user has the option to disable javascript and cookies because not everybody likes the idea of javascript and cookies as handy as they are.

0

Thank you very much...I appreciate very much your help, but my Superior (our team leader) told me..."Please try to use server side scripting because some js may not support every browsers....?
can you tel me please..Is there any browser compatibility problem with my js code block..?

Your "team leader" should also know what is possible and what is not.
It is good practice that important "core features" be all PHP based. Other less important "fancy" features can be JS.
The only way PHP is going to change anything on the screen is if you do a submit and then refresh the screen updates with PHP echo of variables. (or whatever).
That will require a server request.

0

Thank you very much...I appreciate very much your help, but my Superior (our team leader) told me..."Please try to use server side scripting because some js may not support every browsers....?
can you tel me please..Is there any browser compatibility problem with my js code block..?

I think your Superior has an Inferior grasp of the situation. If he is an IT tutor, I'd be looking for a new one. Pure pHp requires form submission, which kind of defeats the idea of automatically populating a formfield when it accepts the focus. I've said it so many ways, this is my last post on the matter: pHp is not the way to go with your original brief (duplicate value of formfield to new formfield on focus).

0

Sorry, I just typed that up quickly and made a couple of typos. This should work:

<?php
if(isset($_POST['submit'])) {
    $valueB = ' value="' . $_POST['inputA'] . '"';
}
?>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<input type="text" name="inputA" />
<input type="submit" name="submit" value="GO" />
<br /><br />
<input type="text" name="inputB"<?php echo $valueB; ?>>
</form>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.