Submitting selection box item when javascript disabled - javascript

This is the case. I want to pass onchange event to a page (actually to the page this call is coming from) without having javascripting available. There is a tag with address like this:
<form name='form1' action='http://mysite.com/index.php' method='get'>
The select tag takes onchange event:
<select name='alue' onchange='this.form.submit();'>
I want to pass a particular, restricted list of choices to another selection box, based on the first selection box selection. I would like this to happen when javascript is disabled but is this impossible? Is this totally a client side event? Is there a way to perform this action purely with php (by forcing the page to reload somehow)?
The point is to have an alternative way for user to restrict amount of choices when javascript is disabled. Thank you for any advice and suggestion!

One approach is following :
Submit the form generally i.e through submit button then you can check in POST variable if the select box was selected or not.
if select box have value you can pass the form data using PHP to your page.

Related

How to use form input to update code?

I have a page where I need to filter certain values provided by an embedded widget based on user input in a text field.
I can do this by appending certain parameters to the widget code embedded on the page and refresh the page
How do I take the user input , replace the widget code and refresh the page?
this is the code I might need to append to the widget code that already exist on my page.
%22filter%22:%7B%22keyword%22:%22userprovidedvalue%22%7D,
I am using jsp
You should be able to handle it by putting an onchange on the input field, and sending it to a function that reads the value off of the input field. Alternately, you can have the submit button call a function, that first reads the value off the input field, then performs whatever logic you need, then submits the form.
Jquery is often useful for making things like this easier and more intuitive, though it does have a bit of a learning curve to ramp up.

Cannot access the value of the selected item of a disabled drop down, in action class (struts 2)

On a Jsp page I have some select elements which were disabled after a value was selected (Disabled them in javascript). Now when the form is submitted, I can not access those selected values in the action class.
I know for sure that this is caused by the select elements being disabled because, when I tried the same without making them disabled, it worked fine.
Now I don't understand why is this so. I thought maybe I should enable them before the form is submitted, but it does not seem a good idea.
I faced this problem while implementing this : Creating struts 2 forms dynamically on jsp using java script .
(You can find the code there. Although I don't think you will need the code, because it is clear where the problem is.)
Here I am able to access the values of text fields but I can not access the values of select elements.
I asked this question separately because I thought this is a different topic.
Thanks!!
Disabled fields by W3 specifications will not get posted on the server side so this issue is not related to the Struts2 but in generic an HTML way to go
Disabled controls
i am not sure why you want to use disabled control for your form.things can be done using readOnly attribute or use hidden fields
You can set them in hidden field through java script and pass it to action

add a text field on click of a link: javascript disabled

How do I add a text field on click of a link inside a form when javascript is disabled? It should not refresh the page and should store the form values which are present earlier.
Since Javascript is disabled, the interaction should occur using a server. You should call an appropriate event on the server and this latter will return the page with an added textfield.

Suggestion needed for NON JavaScript version of an input autocomplete

I'm building an App that is heavy on jQuery. Most of it I can handle without the use of JS and still have a functioning site, however there is one bit that is eluding me. (note, I'm using ASP.NET MVC but that shouldn't matter in this instance)
I have an input field that is making great use of jQuery-UI AutoComplete. The behavior is very simple. The user is asked to input their City, but is given an AutoComplete list of valid cities. If the city is invalid, the server side validation fires and tells them to try again.
If they do select a valid city, the jQuery method updates a hidden field that contains the CityID of the selected city. This is working phenomenally well, and I really like the performance.
Here's where the problem enters. If JS is not available in the browser, the ID field is not updated, and hence the DB is not updated. I am not using the AutoComplete input on the server side at all, just the ID field. What would be a good solution to circumvent this issue?
Default to a select element containing the cities as options and id's as values, and change it to the autocomplete field with the script on page load.
If for some reason sje397's answer doesn't work for you (it's an elegant solution, unless the city auto-select is based on some other field on-screen, such as a zip code or state), simply POST both fields. When evaluating the POSTed data, if the CITY text box has data, and the hidden field does not, then evaluate the entered city using the same validation method used by the jquery callback. If the hidden field has data, you assume that javascript is enabled and use your current logic.
Several options:
1 - Serve HTML initially that shows the "hidden" input, and doesn't include the "autocomplete" one. When JS loads, have a function edit the DOM to your current situation.
2 - Have the form default to send the "autocomplete" data to the server. Use javascript to edit the "send" function to have it switch to the "hidden" input.
Get the page to by default to send the input of the user over the intertubes to your server, if javascript is enabled, change it so it only sends the ID over instead (using javascript obviously).

load a new page when an html's selector changes without javascript

How can I (if at all) load a new page when an html's selector changes if javascript is disabled in the browser.
Can it be done?
I guess you mean the html select box having some page titles displayed and as soon as the user selects one of them the new page showes up.
This is not possible with out javascript - the only thing you could do is to add a submit button.
<noscript><input type="submit" value="go!"></noscript>
This button would only be displayed if javascript is not activated.
No, you cannot reload a page when a select box changes (if that's your question) without using a scripting language or similar.
Without a scripting language (that would be JavaScript if you want to be cross-browser), most form elements are "dumb", they hold their state and display user feedback.
So if you want to select a new page after selecting it in a form (combo box, list, radio buttons...), you have to add a submit button to send the choice to a server, and have a server side script handling the choice and serving the right page.
The good old Web 1.0 way... :-)
You can't. With HTML only, changing the selected option makes the value of that option to be sent to the server upon submit (either via the Enter key or a submit/button element). You can eventually set up the receiving script to send back a HTTP Redirect based according to the selected option.
You shouldn't. This kind of navigation widget implies the use of a mouse: somebody using the keyboard to navigate the page cannot even select the second option at all (as soon as the down arrow is pressed once the onchange() event activates). Do the right thing and add a submit button, with the page change activated by the onsubmit() event.

Categories

Resources