0

I am creating a web site. So, I am creating a registration form in this web site. There are drop down box which have Company name and text field which have address in this form. Now I want to show relevant address in same page when someone change the company name from the drop down box. I am very new to laravel.

How can I do this ??

Here is my Form.

<form class="form-horizontal" method="POST" action="#" enctype="multipart/form-data" id="signupForm">

{{ csrf_field() }}

<br><br>
Address : <input type="text" class="form-control" name="add" value="" id="username">

Company Name :
<select>
  <option value="Com 1">Com 1</option>
  <option value="Com 2">Com 2</option>
</select>

</form>
7
  • If you want to make another server request and do it by assigning a GET or POST variable. But if you want to do it in the same page you might want to try an AJAX request Commented Jun 7, 2018 at 6:51
  • @NirojMaharjan - In the same page.. How can I do it ?? Commented Jun 7, 2018 at 6:52
  • you can make a function that will show you the relevant address from the company name and then call it using AJAX and append it on your HTML. Commented Jun 7, 2018 at 6:54
  • @Amithash You create one controller where pass company id as parameter that controller return address value and that controller url call in ajax function that ajax function is called on onchange event on company select box. Commented Jun 7, 2018 at 6:55
  • @Amithash If you don't know know ajax then you can check this link where one demo is that related dropdown change event of city and state dropdown. expertphp.in/article/… Commented Jun 7, 2018 at 7:00

1 Answer 1

1

You have to use jquery :

$(document).ready(function(){
   $('#company').val('Com 1');
   $('#company').trigger('change');
});

$(document).on('change','#company',function(){
  if($(this).val()=='Com 1'){
    $('#address').val("Address of Company 1");
  }else if($(this).val()=='Com 2'){
   $('#address').val("Address of Company 2");
  }
  else{
     $('#address').val("Default Address");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Address : <input type="text" class="form-control" name="add" value="" id="address">

Company Name :
<select id="company" name="company">
  <option value="Com 1">Com 1</option>
  <option value="Com 2">Com 2</option>
</select>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.