3

I have a drop-down which will display the phone numbers on click of which I need to submit a form in JavaScript disabled browser.

Currently I am doing the following stuff:

<form action="/servlet/myservlet" method="GET">
    <select name="myselect" id="myselect" onchange="this.form.submit()">
        <c:forEach items="${mydata.phoneNumbers}" var="phoneNumber">
            <option value="${phoneNumber}">${phoneNumber}</option>
            </c:forEach>

Or is there any way to achieve the same withe below bootstrap code with JavaScript disabled

<button class="dropdown-toggle" type="button" id="prefix-num" data-toggle="dropdown"> ${mydata.phoneNumber}</button> <ul class="dropdown-menu dropmenu-menu-custom" role="menu" aria-labelledby="prefix-number-1"> <c:forEach items="${mydata.phoneNumbers}" var="phoneNumber"> <li><a href="/servlet/myservlet" class="changeNumber" role="menuitem">${phoneNumber}</a></li> </c:forEach> </ul> 

But once I click on drop-down values form is not getting submitted.

2
  • are you want to submit the form without using javascript? Commented Jan 31, 2016 at 9:24
  • 2
    this.form.submit() not worked in JS disabled browser Commented Jan 31, 2016 at 9:39

2 Answers 2

6

You need a type="submit" button to submit the form without JavaScript. There's no other way.

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

Comments

1
<form action="/servlet/myservlet" method="POST">
    <select name="myselect" id="myselect" onchange="this.form.submit()">
            <c:forEach items="${mydata.phoneNumbers}"
                                            var="phoneNumber">
                     <option value="${phoneNumber}">${phoneNumber}</option>
                                        </c:forEach>
    </select>
    <input type="submit" name="sub_btn" value="Submit">
</form>

Please add submit button control to submit the form without JavaScript.

Also, use POST method instead of GET otherwise your form data will get passed in query string of URL.

2 Comments

But i want to submit the form on click of dropdown values is that possible??
Or is there a way to achieve the same withe below bootstrap code with javascript disabled- <button class="dropdown-toggle" type="button" id="prefix-num" data-toggle="dropdown"> ${mydata.phoneNumber}</button> <ul class="dropdown-menu dropmenu-menu-custom" role="menu" aria-labelledby="prefix-number-1"> <c:forEach items="${mydata.phoneNumbers}" var="phoneNumber"> <li><a href="/servlet/myservlet" class="changeNumber" role="menuitem">${phoneNumber}</a></li> </c:forEach> </ul>

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.