Can you check again I have tried your process thrice
its same value that I left not “select course”
Can you check again I have tried your process thrice
its same value that I left not “select course”
Using Chrome version 42 it seems to work.
Internet Explorer version 11 seems good too.
Even on my cell phone (Nokia Galaxy S5) it works.
What are you testing with?
Or to phrase it another way - how can I experience the problem that you are having?
I am trying it on jsfiddle
Have you tested it on jsfiddle?
Yes, jsfiddle is where I have been visiting with each of those web browsers to test your code, at http://jsfiddle.net/b0hbk495/44/
What precise steps are you taking that result in failure, and what does that failure look like.
If others can experience the same problem that you are having, we’ll be able to make progress then.
You are right
My Mistake
its working fine thanks
issue was with my web browser.Tested in other browser working fine as expected thanks
Okay, now we’re getting somewhere.
What is the browser that was having trouble? We have ways of making them work too.
its not because of browser
its because some plugin installed in browser.
By removeing it working in all browser
What was the plugin that was causing the problem? I want to fix the code so that it works even when that plugin is there.
wait
have you tested this code
in mozilla firefox?
its still not working there
for Input it is working but for select it is not working
Thank you, I can now experience the same problem, and shall test from there.
The problem in your code is that the attribute was being changed.
For compatibility with Firefox, you need to change the property of the select element instead. That is the correct way of updating a select box.
Change .attr to .prop and it will work.
Now its working fine in all web browser
can you explain a little bit difference between .attr and .prop?
Sure thing. Elements of the page have attributes.
For example, with the select element, it has an attribute called name, with a value of userCourse
select name="userCourse">
All of the HTML code that you write are elements with attributes and values.
When the page gets loaded in to the web browser, the source code is converted in to an internally represented tree structure called the DOM (Document Object Model) which is where attributes are converted in to properties.
When you from JavaScript access a form element, the properties of the element are the most common way for you to access information about them.
var select = document.querySelector('select');
select.selected = 'selected';
If you want to change the attribute of that element, it requires using the setAttribute method call instead.
var select = document.querySelector('select');
select.setAttribute('selected', 'selected');
Most web browsers update the DOM when an attribute is changed. That behaviour is not common across all web browsers.
As it says on the setAttribute documentation page:
The jQuery .attr documentation page also has this useful insight to share:
[quote]Nevertheless, the most important concept to remember about the checked attribute is that it does not correspond to the checked property. The attribute actually corresponds to the defaultChecked property and should be used only to set the initial value of the checkbox. The checked attribute value does not change with the state of the checkbox, while the checked property does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property:
The same is true for other dynamic attributes, such as selected and value.[/quote]
So for all of the above reasons and more, .prop is the correct way for jQuery to update an element.
I should have remembered that as I’ve come across it before
Yes - I came across it a while ago when jquery added the .prop statement and stopped .attr from updating both.
For the record, here’s the updatelog from jQuery 1.9 that explains how .prop was added in 1.6, and how from 1.9 the .attr behaviour was to be changed. https://jquery.com/upgrade-guide/1.9/#attr-versus-prop-
Thanks Paul
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.