473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

coding an if condition

Hello,

On a html form I have a text area where user can post comment.
There is an initial value with indications for the user to read, but when he clicks on the field the comment dissapears letting him write his own comment.

This field is enabled to receive a null value, and that is what I want to happen when the user doesn't write on it. But right now if the user don't write on it, it is storing the initial value ¨type here your comment¨ here is the code:[php] <textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
(this.value==this.defaultValue) this.value='';">type here your comment
</textarea>[/php]


I have the idea on how to do it, but don't know how to code it correctly
here is my idea:
[php]<?php
if (['coment']=¨Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.¨ {['coment]='null'}
?>[/php]Thanks for any help,

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

MODERATOR
Mar 14 '08 #1
9 1757
Markus
6,050 Expert 4TB
Hello,

On a html form I have a text area where user can post comment.
There is an initial value with indications for the user to read, but when he clicks on the field the comment dissapears letting him write his own comment.

This field is enabled to receive a null value, and that is what I want to happen when the user doesn't write on it. But right now if the user don't write on it, it is storing the initial value ¨type here your comment¨

here is the code:

<textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
(this.value==this.defaultValue) this.value='';">type here your comment
</textarea>


I have the idea on how to do it, but don't know how to code it correctly
here is my idea:

<?php
if (['coment']=¨Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.¨ {['coment]='null'}
?>


Thanks for any help,
[php]
if($comment == "Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.")
$comment = null;
[/php]
Mar 14 '08 #2
[php]
if($comment == "Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.")
$comment = null;
[/php]
I have coded exactly what you told me but nothing happens, still storing the initial text. Also tried using { } for the if instruction, using "nul", using 'null' ect. but nothing seems to work. Also I tried deliting the word "aquí" from the text to avoid problems generated by the accent (í). but nothing seems to work.
Mar 15 '08 #3
ronverdonk
4,258 Expert 4TB
The value of your textarea is 'Search'. You specified that yourself in the textarea statement, i.e. [php]value="Search"[/php].Ronald
Mar 16 '08 #4
I tried shortening the text in the comment area tu just "ingresa" (no capital letters, no spaces) and I figured out a code that do the job:

Expand|Select|Wrap|Line Numbers
  1. if($_POST['comentario'] == "ingresa%")
  2. {
  3. $_POST['comentario'] = ""; 
  4. }
  5.  


but when putting a long text in the comment area (as I need to), the if condition doesnt work, or doesent make the match as it should, maybe it is because of the caps and spaces.

Any solution for making the condition work with a long text?
Mar 31 '08 #5
arggg
91
It should not check for case sensitivity unless you use ===

try

Expand|Select|Wrap|Line Numbers
  1. if(fnmatch("ingresa*",$_POST['comentario']))
  2. {
  3. $_POST['comentario'] = "";
  4. }
  5.  
Mar 31 '08 #6
TheServant
1,168 Expert 1GB
It should not check for case sensitivity unless you use ===

I thought === was only for checking if the type is the same as well, not case sensitivity?
Mar 31 '08 #7
Markus
6,050 Expert 4TB
I thought === was only for checking if the type is the same as well, not case sensitivity?
It seems logical that "hello" is not equal to "Hello" - i think that's how php understands it. So, therefore, PHP neither == or === will see them as being equal.

As TheServant rightly said === checks for the type of the value being passed.

I.E it checks whether 11(int) is equal to "11"(string) - because one is a string and the other an interger, they are not equal.

/ramble.
Mar 31 '08 #8
bucabay
18
Hello,

On a html form I have a text area where user can post comment.
There is an initial value with indications for the user to read, but when he clicks on the field the comment dissapears letting him write his own comment.

This field is enabled to receive a null value, and that is what I want to happen when the user doesn't write on it. But right now if the user don't write on it, it is storing the initial value ¨type here your comment¨ here is the code:[php] <textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
(this.value==this.defaultValue) this.value='';">type here your comment
</textarea>[/php]


I have the idea on how to do it, but don't know how to code it correctly
here is my idea:
[php]<?php
if (['coment']=¨Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.¨ {['coment]='null'}
?>[/php]Thanks for any help,

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

MODERATOR
There are a few problems going on here:

The first is in the javascript.


Expand|Select|Wrap|Line Numbers
  1. <textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
  2. (this.value==this.defaultValue) this.value='';">type here your comment
  3. </textarea>
You have defined in the HTML that the value="Search". So when the user will cick on the <textarea> the text will not disappear.

You should remove the value attribute, and add a defaultValue attribute. (note that defaultValue would be invalid xHTML, as xHTML requires lowercase, so better to make it default_value).

Example:

Expand|Select|Wrap|Line Numbers
  1. <textarea name="coment" id="coment" cols="32" rows="5" default_value="type here your comment" onfocus="if
  2. (this.value==this.default_value) this.value='';">type here your comment
  3. </textarea>
The other problem could be in the content encoding.

Your string: Ingresa aquí cualquier detalle
importante para el piloto, como que tipo de equipaje llevas.

contains some characters that require multibye character encoding. PHP has problems with this, since it treats all strings as single bytes, and does not consider encoding, unless you tell it to.

see: http://www.phpwact.org/php/i18n/charsets

So if you got the encoding wrong, then your string comparison would fail.

That would explain why a shorter string worked for you, since it does not have the character í which requires multibyte encoding.

Another thing that can cause a problem is the editor you used to write your HTML code. They sometimes add a linebreak in between your HTML tags. Or you could have entered it when you pressed enter.

Consider:

<textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
(this.value==this.defaultValue) this.value='';">type here your comment
</textarea>

This actually has a linebreak:

So "type here your comment"

is actually "type here your comment\n"

(or "type here your comment\r\n" depending on the system you used.)

So in your PHP code that compares the strings, its good to remove the ending and begining line breaks first using the trim() function.

http://www.php.net/trim/
Apr 1 '08 #9
There are a few problems going on here:

The first is in the javascript.


Expand|Select|Wrap|Line Numbers
  1. <textarea name="coment" id="coment" cols="32" rows="5" value="Search" onfocus="if
  2. (this.value==this.defaultValue) this.value='';">type here your comment
  3. </textarea>
You have defined in the HTML that the value="Search". So when the user will cick on the <textarea> the text will not disappear.
No problems with the disappearing text, it works like it was.
Anyway, thanks for the advice for the second problem! (you don't sound like a newbie)
Apr 1 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Zhang Weiwu | last post by:
Hello. I have a question that spining around my head for a long time. I prefer to make this kind of if statement: if (!$GLOBALS) Header( 'Location: '.$GLOBALS-> link('/',...
63
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
60
by: Eric | last post by:
I thought it might be fun to run a simple vote to discover the most preferred spacing style for a simple if statement with a single, simple boolean test. By my count, there are 32 possible...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
0
by: lovecreatesbeauty | last post by:
Some of the coding guideline are mandatory, and even the format or layout of the text of the source code also should be followed. There's plenty of codes like the following snippet. Do you think...
2
by: TT (Tom Tempelaere) | last post by:
Hi I'm reading the C# coding standard and I don't understand the following item (38) 38. With delegates as class members a) Copy a delegate to a local variable before publishing to avoid...
12
by: kalinga1234 | last post by:
hy guys i am having a problem with my sudoku program which i coded using c++.; currently in my program if a duplicate number exist in either row/column/block i would make the particualr square...
52
by: Sergey Zuyev | last post by:
Hello All I work at software company and we are having a really big discussion about coding styles and it seems that more people prefer statement 1 to statement2 , which was a big surprise to...
3
by: bh | last post by:
If I want to loop through the values in a listbox, and get either all items in the box, or only selected items, based on a boolean variable passed into a subroutine, which method would be more...
1
by: flavourofbru | last post by:
Hi, I am stuck at a major part of the code in VC++. My algorithm is as follows: f_name = load(filename); //this also loads a text file. The text files contains numbers sepearted by tab....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.