0

I want to be able to have a text box on a page where php writes into and javascript read from

I saw this solution How can I set the value of a textbox through PHP?

use it and I manage to write the value on the textbox using this command

<input type=\"text\" name=\"txtFromPHP\" value=\"" .$row['id'] . "\">

but when I access the textbox usng this

var str = document.getElementById('txtFromPHP').value;

I get error

document.getElementById("txtFromPHP") is null

Just maybe it's relevant, my html page where textbox is placed is a modified version of Ajax Database example found at http://www.w3schools.com/PHP/php_ajax_database.asp

Thanks

0

2 Answers 2

1

You need to set the element ID as follows

<input type=\"text\" id=\"txtFromPHP\" name=\"txtFromPHP\" value=\"" .$row['id'] . "\">

In your example you only set the name of the element txtFromPHP and did not set an ID

Sign up to request clarification or add additional context in comments.

Comments

1

change the "name" to "id" or have them both:

<input type=\"text\" id=\"txtFromPHP\" value=\"" .$row['id'] . "\">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.