JAVA script Jquery PHp

My Problem is if i enter a Place in first text box the second textbox will be change base on if statement condition in first textbox
JerickStarkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Uhh?  Can you please share a public and clickable link to the web site that illustrates your question?  Maybe if you can show us the problem event in action we can offer some helpful ideas.
1
JerickStarkAuthor Commented:
Like this but this one is not functionnable

<HTML>
            <head>
                        <meta charset="utf-8">
                  <title>Trojanator.Homepage</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="CSS/style_tut.css" rel="stylesheet" type="text/css">
      <script src="js/alert_tut.js"></script>
      <link href="js/bootstrap.min.css" type="text/css" rel="stylesheet">
      <script src="js/jquery.min.js"></script>
      <script src="js/bootstrap.min.js"></script>
            </head>


<form>
<input type='text' id='res' />
<br/>
<select id='aa'>
    <option value='City1'>Pampanga</option>
    <option value='City2'>Tarlac</option>
    <option value='City3'>Batangas</option>
</select>





<script>
var result = $('#res');
var aa = $('#aa');

result.on('keydown keyup', function () {
    if (result.val= ('Angeles')) {
       $('option[value="City1"]', aa).prop('selected', true);
    } else if (result.val = ('Mabalacat')) {
        $('option[value="City1"]', aa).prop('selected', true);
    }
});
</script>
</form>
</HTML>
0
Marco GasiFreelancerCommented:
Hi. First you're selecting always City1, so you never can see any change. Second you have to wrap your jquery in $(document).ready block.
Anyway, here you find the right jQuery code to do what you want: I set to select City2 fo Angeles and City3 for Mabalacat to make chenges evident):
    <script>
      $('document').ready(function () {
        var result = $('#res');
        var aa = $('#aa');

        result.on('keyup', function () {
          if (result.val() === 'Angeles') {
            alert('city1');
            aa.val('City1');
          } else if (result.val() === 'Mabalacat') {
            alert('city2');
            aa.val('City2');
          }
        });
      });
    </script>

Open in new window


Cheers
1
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JerickStarkAuthor Commented:
Thanks a lot sir Marco
0
JerickStarkAuthor Commented:
sir there is a choices to not  enable the alert ?
0
Marco GasiFreelancerCommented:
Ooops, I forgot tyo drop them! Just delete them:
    <script>
      $('document').ready(function () {
        var result = $('#res');
        var aa = $('#aa');

        result.on('keyup', function () {
          if (result.val() === 'Angeles') {
            aa.val('City1');
          } else if (result.val() === 'Mabalacat') {
            aa.val('City2');
          }
        });
      });
    </script>

Open in new window

Forgive my mistake, please.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JerickStarkAuthor Commented:
Thank you Sir :D
0
Marco GasiFreelancerCommented:
Glad to help you and welcome at Experts-Exchange. I see this is your first question and I suspect you don't know what you have to do now, am I wrong?
When one or more experts give you the solution to your problem, you have to accepts his/their comment as solution. Look at any comment box: you'll see two clickable links 'Accept as multiple solution' and ' Accept as solution': click the right link and follow the instructions. When you choose the grade, keep in mind that usually the grade must be 'A', unless the expert have been evidently negligent.
Hope this helps you to use Experts-Exchange.
Cheers
0
Julian HansenCommented:
This looks like homework
<link href="CSS/style_tut.css" rel="stylesheet" type="text/css">
      <script src="js/alert_tut.js"></script>
If it is you need to state it is as such and we can then help you find a solution rather than posting a complete solution to the problem.

Some pointers on your code so far

1. Consider putting your jQuery inside a document load function
Either
$(document).ready(function() {
...});

Open in new window

Or
$(function() {
});

Open in new window

2. Look at the jQuery .change or .blur functions - rather than the .keydown. The former fire after a complete entry has been made whereas keydown fires every time you press a key. Keydown can work but it results in unnecessary calls to your event handler.

3. You can set the selected item in a select more easily like this

$('#aa').val('City1');

Open in new window


Try the above changes - let us know about the homework / assignment and we can take it from there.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.