converting string to number in jscript

Results 1 to 3 of 3

Thread: converting string to number in jscript

  1. #1
    Join Date
    Dec 1969

    Default converting string to number in jscript

    I am reading in the VALUE of a check box which is either "True" or "False" and trying to convert it to true or false (BOOLEAN) which I can use to set the checked state.<BR><BR>frm.cancelled.checked = frm.cancelled.value.toLowerCase;<BR><BR>frm.cancel led.value.toLowerCase is returning a string containing "true" or "false" and it does not set frm.cancelled.checked correctly so I am assuming it is string that needs to be converted to a BOOLEAN value<BR><BR>Thanks in advanced for your help.<BR><BR>Rudi

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default hmmmm

    how about <BR><BR>if (frm.cancelled.value.toLowerCase){<BR>frm.cancelle d.checked = true<BR>}else{<BR>frm.cancelled.checked = false<BR>}

  3. #3
    Join Date
    Dec 1969

    Default You *BOTH* forgot...

    ...that JavaScript *INSISTS* on having ( ) after function calls! Even calls that take no arguments.<BR><BR>When you omit the ( ), you end up getting a number that is the *address* of the function in memory! Pretty useless.<BR><BR>Akhilesh: I dunno if your trick works, but if it does you&#039;d code it as:<BR><BR>if (frm.cancelled.value.toLowerCase[hl="yellow"]( )[/hl]){<BR> frm.cancelled.checked = true<BR>}else{<BR> frm.cancelled.checked = false<BR>}<BR><BR>But I think it makes more sense to code<BR><BR> frm.cancelled.checked = ( frm.cancelled.value.toLowerCase( ) == "true" );<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts