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
if value of field X is Y then value of Field A is B
Moderator: General Moderators
Re: if value of field X is Y then value of Field A is B
Easy answer... Use javascript with an onblur event to auto fill the second input box with whatever value you want.
Re: if value of field X is Y then value of Field A is B
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>
Re: if value of field X is Y then value of Field A is B
Just be aware that a small proportion of Web viewers (estimated at below 5%) may have Javascript disabled.danwguy wrote:Easy answer... Use javascript with an onblur event to auto fill the second input box with whatever value you want.
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.
Re: if value of field X is Y then value of Field A is B
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
thanks for the reply