LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2021, 07:53 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
Showing <textarea> value in <form> (value from php)


<textarea> values came from a query of my Database:
$query="SELECT * from hdata WHERE Id=".$recId.";";
part of the hdata returned data is - $row['tests'], $row['results'], $row['notes']

I want these values to show up in my <form>> So I have a chance to edit them if I want.

Code:
<form>

 ...... Other input data  .....

<textarea name='tests' id='tests' rows="3" cols="40" value='<?php echo $row[tests]; ?>'></textarea><br>
	
<textarea name='results' id='results' rows="3" cols="40" value='<?php echo $row[results]; ?>'></textarea><br>

<textarea name='notes' id='notes' rows="3" cols="40" value='<?php echo $row[notes]; ?>'></textarea><br>

</form>
I know that <textarea> doesn't have a 'value' attribute so how do I accomplish setting the <form> <textarea>'s to show the php values?

See Insert to show what this code does. NOTE: Not using ' ' around tests. results, and notes.
Attached Thumbnails
Click image for larger version

Name:	Selection_051.png
Views:	20
Size:	22.8 KB
ID:	36765  

Last edited by pizzipie; 07-09-2021 at 08:18 PM.
 
Old 07-09-2021, 08:06 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Just put it inside the element, that is between the opening and closing tags.

Code:
<textarea ...><?php echo value here ... ?></textarea>
This is no different than most other HTML markup, like paragraphs, spans, etc.

Consider the difference between an element's attributes and its content. Attributes are name="value" pairs inside the angle brackets with the element name, but content goes between the opening and closing tags.

Code:
<p style="...">Something else here</p>
<span id="42">More stuff here</span>
<textarea name="myself">Whatever you want to edit here</textarea>
...where style, id and name are attributes, and the visible content is always between the opening and closing tags.

One exception is the input element which has a value attribute but does not expect content between the opening and closing tags and is normally self closing.

Code:
<input name="me" value="something" />
In this limited view, you may think of the input element, and some other form elements, as a kind of exception, and textarea as having the "normal" or expected behavior. Actually the input element is simply defined to have a different behavior and is an empty element in that it has no content, but it does have a visible value attribute.

Last edited by astrogeek; 07-09-2021 at 08:46 PM.
 
Old 07-13-2021, 01:19 PM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thanks Astrogeek.

Quote:
Just put it inside the element, that is between the opening and closing tags.
This did not work.

What I did is:

Get php/mysql data, Create Form, Populate the form with php/mysql data. No problems here.

Code:
 if(isset($_GET)) { 
		$recId=$_GET['recId'];
		$patient=$_GET['patient'];

//myprint($_GET);

$cxn = mysqli_connect($hostname,$username,$password,$database)  or die ("Error " . mysqli_errno($cxn) ." ". mysql_error()); 

$query="SELECT * from hdata WHERE Id=".$recId.";";

$result = mysqli_query($cxn, $query)  or die ("Query Error " . mysqli_errno($cxn) ." ". mysql_error()); 
$row = mysqli_fetch_assoc($result);

mysqli_close($cxn);
}
Code:
<label class='Label1'  for='place'>Place</label>
	<input   type='text' name='place' id='place' ><br>
	<label class='Label1'  for='tests'>Tests</label>
	<textarea name='tests' id='tests' rows='3' cols='40' ></textarea><br>
	<label class='Label1'  for='results'>Results</label>
	<textarea name='results' id='results' rows='3' cols='40' ></textarea><br>
	<label class='Label1'  for='notes'>Notes</label>
	<textarea name='notes' id='notes' rows='3' cols='40' ></textarea><br><br>
	<input type="submit" class="hov" value="Update">
	<input type="button" class="hov" value="Revision OK Go Back"  onclick="window.location.href='healthFrontEnd.php'";>
	</form>
	</div> <!-- form -->
	
<script type="text/javascript" >
// populate the form

 $("#id").val("<?php echo $row['id']; ?>");
 $("#patient").val("<?php echo $row['patient']; ?>");
 $("#doctor").val("<?php echo $row['doctor']; ?>");
 $("#pharmacy").val("<?php echo $row['pharmacy']; ?>");
 $("#date").val("<?php echo $row['date']; ?>");
 $("#place").val("<?php echo $row['place']; ?>");
 $("#tests").val("<?php echo $row['tests'];?>");
 $("#results").val("<?php echo $row['results'];?>");
 $("#notes").val("<?php echo $row['notes'];?>");
 
Old 07-13-2021, 02:17 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
But you are not doing the thing I suggested at all.

Please try to be more precise when thinking about how the various pieces interact, and understand what each one does in what context - and verify that operation before writing complete sections of code that rely upon them and before declaring they "don't work".

The jQuery val() method sets the value attribute of HTML form elements that have them.

But in your original post you state:

Quote:
I know that <textarea> doesn't have a 'value' attribute so how do I accomplish setting the <form> <textarea>'s to show the php values?
So I must ask why you are trying to set an attribute which you know does not exist? The most obvious answer is that you have not yet understood what that means, or learned the same basic lesson from your other thread here.

So in the interest of trying to help you understand, please pause and think about what I meant by this:

Quote:
Just put it inside the element, that is between the opening and closing tags.
Code:
<textarea ...><?php echo value here ... ?></textarea>
... and why the new code you have posted does not do that.

You should then be able to adapt your jQuery code to do the right thing (hint: see that other thread), or simply echo those values inline in the right place in the HTML and not use jQuery for that at all (my preference given your example). Work out simple examples doing it both ways and see which best meets your needs - and most importantly, learn how it works and why!

Keep it simple, see if you can get an example of that working, let us know if you are still having trouble.

Good luck!

Last edited by astrogeek; 07-13-2021 at 02:26 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
insert text messge in textarea using php and connection error? intentclears Programming 4 12-14-2010 09:26 AM
difference between value *value and value * value PoleStar Linux - Newbie 1 11-26-2010 03:37 PM
[SOLVED] Textarea php wysiwyg editors? vesperto Programming 6 10-12-2009 10:38 PM
PHP: build query from form entry, then display results in the same form tonedeaf1969 Programming 4 06-22-2007 07:55 AM
QT showing another form from one form juby Programming 0 07-09-2003 02:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration