X.value problem

Joined
Mar 27, 2024
Messages
3
Reaction score
0
Can't find what's wrong in my following code. See my notes in my code.
function formcheck(myform)
{with (myform)
alert(sel.value); <----note---------- Msg shows a "2"
if(sel.value==2)
{alert('OK');} <-----note--------- This msg never shows up and it should because above msg shows 2.
else{alert('not 2');return false;} <-----note-------Msg shows "not 2" and this should not happen a/c above msg shows a 2.
if(frdate.value == '' && todate.value == '')
{alert('TO DELETE A RANGE, DATES ARE REQUIRED.');return false;}}

"sel" is in HTML <input type='radio' name='selfunc' id='sel' value='2'>
Thanks for your help
 
Joined
Apr 25, 2017
Messages
248
Reaction score
32
your sel.value is int or String? Different datatype will show different result.
 
Joined
Mar 27, 2024
Messages
3
Reaction score
0
In my radio button, value='2'. I presume that's a String but I've tried
sel.value=='2', ==2, ===2, ==='2' with corresponding value in my radio button but nothing works.

Resolved
new code:
with (myform)
var mysel=sel.value
if(mysel==2)
bla, bla bla

and it works perfectly. But I still don't understand why the other code didn't work. It seems to me it was valid coding.

Thanks for your help
 
Joined
Jul 4, 2023
Messages
356
Reaction score
41
Have you tried this way
Java:
function formcheck(myform) {
    with (myform) {
        alert(sel.value); // This should alert the value of the selected radio button
        if (sel.value.equals('2')) {
            alert('OK'); // This should show up if the value is '2'
        } else {
            alert('not 2'); // This should show up if the value is not '2'
            return false; // If the value is not '2', return false
        }
        if (frdate.value.equals('') && todate.value.equals('')) {
            alert('TO DELETE A RANGE, DATES ARE REQUIRED.');
            return false; // If both date fields are empty, return false
        }
    }
}
to avoid creating another temporary variable
Java:
var mysel = sel.value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top