0

I need to submit combo box value with out form. When I click on any value of combo that suppose to submit automatically using javascript. I am using PHP in backend.

<select name="select" id="select" style="width:50px;">
  <option value="25">25</option>
  <option value="50">50</option>
  <option value="100">100</option>
  <option value="All">All</option>
</select>
3
  • 1
    I would imagine you need the change handler. Commented Sep 23, 2011 at 4:03
  • Are you using any javascript library like prototype or jQuery? Commented Sep 23, 2011 at 4:04
  • Have you written any javascript yet for the page? If so, then please include it in the Q. Commented Sep 23, 2011 at 4:14

3 Answers 3

2

Here a js part:

function getinfo() {
  var aList = document.getElementById("select");
  var val = aList.options[aList.selectedIndex].value;

  // document.write("<p>Here what you select: "+val+"</p>");
  // here you can send `val` to the server using... are you using any js library?
}

And you need to change your select declaration:

<select name="select" id="select" style="width:50px;" onchange="getinfo()">
                                                      --------------------
</select>

OK, how to send val to the server is another question... If you are using jQuery - you can use jQuery.ajax(...) or any helper like jQuery.get(...). If you are vanilla-js user you can use XMLHttpRequest way and if you use any other lib - just check this lib's documentation to get helped about sending data to the server.

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

Comments

1

You can use the methods below.

1) Use Session or Cookie to send external data

2) Send a POST request using XMLHttpRequest in javascript.Checkout the link here.

3)You can use cURL function to send HTTP POST request. Please go through the link here.

Comments

0

Some comments:

  • The select element should always be inside a form. But you don't need to expose the form on the page--you do not need to include a submit input element.

  • You can use Javascript (JS) to submit the form after the user has changed the value of the select.

  • Or you can use JS with Ajax to submit the form asynchronously in the background--the user will not be aware that the data had been submitted and the page will not reload or "flash"

What would you like to do?

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.