Put a value from PHP to INPUT Text?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jpor
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2009 10:56 pm

Put a value from PHP to INPUT Text?

Post by jpor »

I have a INPUT Text and I give it, through PHP, values depending on the research I do to a database.
Something like that:

Code: Select all

...
<input name="erro" id="erro" value="">
...
<?php
...
echo "document.getElementById('erro').value='Dados Correctos';";
...
?>
But not work.
RiMMER
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2009 10:29 pm

Re: Put a value from PHP to INPUT Text?

Post by RiMMER »

I don't get what you want to do.

Do you want to take data from SQL and put it into value="" inside the input tag?
jpor
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2009 10:56 pm

Re: Put a value from PHP to INPUT Text?

Post by jpor »

RiMMER wrote:I don't get what you want to do.

Do you want to take data from SQL and put it into value="" inside the input tag?
I have the Input Text with a value. With PHP, I do the SQL Query, and, depending this Query, I modify value of the Input Text and show again this Input.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Put a value from PHP to INPUT Text?

Post by papa »

Sure you have the correct JS syntax?
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

Re: Put a value from PHP to INPUT Text?

Post by juma929 »

Hello,

I dont fully understand either what you are trying to achieve...

Putting a value into a text entry box...

<?php

$someValue = "test";

echo '<input type="text" value="' . $someValue . '" />';

?>

Thanks,
Justin
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Put a value from PHP to INPUT Text?

Post by McInfo »

You can fill an input using Javascript, but that would not be my first choice.

Code: Select all

<?php
$value = 'abcdefg';
?>
 
<p>Filled by Javascript : <input type="text" id="txtExample" value="" /></p>
<script type="text/javascript">
document.getElementById('txtExample').value = '<?php echo $value; ?>';
</script>
 
<p>Filled by PHP : <input type="text" value="<?php echo $value; ?>" /></p>
Edit: This post was recovered from search engine cache.
Post Reply