if value of field X is Y then value of Field A is B

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
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

if value of field X is Y then value of Field A is B

Post by inosent1 »

hi

my user fills out a form. in the first filed called 'name' the user places their name

then i have another field, 'result', underneath that i want to use to evaluate the input of the 'name' field, and based on its contents, place a value in the result field.

example

name: jones

result field: "if 'name' = 'jones' then value=blue"

so then upon submission, what will get fed to the MySQL DB will be these two values

name: jones
result: blue

not sure how to go about this
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: if value of field X is Y then value of Field A is B

Post by danwguy »

Easy answer... Use javascript with an onblur event to auto fill the second input box with whatever value you want.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

Re: if value of field X is Y then value of Field A is B

Post by inosent1 »

this is what i am talking about, i just dont know how to use php code to 'read' what was entered into the 'name' field, to make the proper evaluation

Code: Select all

    <textarea  name="filenotes" rows="10" cols="80"> <?php 
if ( $name == jones ) {
	echo "blue";
} else {
	echo "red"; 
}

?>
</textarea>      
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: if value of field X is Y then value of Field A is B

Post by califdon »

danwguy wrote:Easy answer... Use javascript with an onblur event to auto fill the second input box with whatever value you want.
Just be aware that a small proportion of Web viewers (estimated at below 5%) may have Javascript disabled.

But to the original poster, what is it you are trying to accomplish? Is this data necessary to be displayed to the user? Could you do this after the form is submitted to the server? The point is that the way the Web works, some things just can't be done, including execution of Javascript (and thus AJAX) if the user's browser has disabled scripts. It's up to the developer to decide how important it is that all viewers have the desired functionality. In some cases, traditional Javascript functionality may be supplied by CSS. Sometimes, though, you have to consider solutions that require sending a new HTTP request to the server for a new page.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

Re: if value of field X is Y then value of Field A is B

Post by inosent1 »

i would prefer the value show up in the field prior to submission. i am not worried about the 5%. it doesnt matter if the user cant see it in the field, as long as the php code can make the evaluation of what 'name' says, and then customize the value of 'result' accordingly to post

thanks for the reply
Post Reply