Input type="text" field does not fill data with more than one word

Asked

Viewed 360 times

2

When loading a data into an input only the first word is loaded. Example:

'</form> <input type="text" value='.$result->name.' >';

$result->name contains the value "Hello World". Since the input only shows "Hello".

Can someone help with that?

  • If you do echo $result->name; what gives?

  • add an ID to the input, and you can test, Document.getElementById('inputText'). value = <?php $result->name ?>

3 answers

3


I believe the problem is the lack of quotation marks on the value="", he is treating the word "World" as if it were an attribute of the text field, ie its output should be: <input type="text" value=Ola Mundo>, to solve this, you need to put the quotes:

'</form>'."<input type=\"text\" value=\"{$result->name}\">";

You can do it like this:

'</form><input type="text" value="'.$result->name.'">';

2

<input type="text" value="'.$result->name.'">

add (")

or

document.getElementById('inputText').value = <?php $result->name ?>

0

Try to use the attribute maxlength and put quotes in value:

'</form> <input type="text" maxlength="100" value="'.$result->name.' ">';
  • That’s right! Little things that grab us ;) Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.