Take a look at this fiddle: here.
I am trying to grab the values of the inputs with the jquery code you see.
Is there anything wrong with this specific code?
Take a look at this fiddle: here.
I am trying to grab the values of the inputs with the jquery code you see.
Is there anything wrong with this specific code?
Itâs because both your inputs have the same class name. The JS doesnât know which one is being referred to. Normally, youâd use the ID property for JS selections, as they have to be unique, that way the JS can be used to âinspectâ its value.
Also, I think you need to look at how your HTML is structured, as I think you need a little more than you have create a mutually exclusive yes/no option.
what is wrong with that?
the code works perfectly OKâŚI was just asking anywayâŚbut the bottom line is that I CAN get the value that the user selected.
Youâll have to excuse me, diagnostics on a phone from a hospital bed has itâs pitfallsâŚ
Well there is no checked input element on the page, so the console just logs undefined; and when the user at some point makes a selection, the script has long terminated. However, you can add event listeners to those elements:
$('.price_show').on('change', function () {
console.log(this.value)
})
These will keep listening to âchangeâ events, and execute the 2nd argument function whenever one is triggered.
You are right about event listenersâŚI do not use the change event thoughâŚI do something else-let me explain.
This is data the needs to go to the server as part of an ajax request.This request is triggered when the user clicks a button:
$('#saveserv').click(function(e){
var priceshow=$('.price_show:checked').val();
//ajax request
})
so the only handler here is the click of the button.Tell me what you think.If the user chooses another radio button then clicking the save button will take into account this change.
So⌠whatâs the problem?
I never said that necessarily there was a problemâŚI just want to hear some views.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.