www.webdeveloper.com
Results 1 to 12 of 12

Thread: [RESOLVED] Unable to pass value to function

  1. #1
    Join Date
    Oct 2011
    Posts
    19

    resolved [RESOLVED] Unable to pass value to function

    I was writing a reusable function for checking and unchecking some checkboxes according to button cllicks. But I am unable to pass the "id" param through the function call.

    Please help.

    Code:
    function checkorUncheck(id)
    {
    if(document.getElementById("id").checked == false)
    	{
    	document.getElementById("id").checked = true;
    	}
    	else
    	{
    	document.getElementById("id").checked = false;
    	}
    
    }
    Function is called here.
    Code:
     lHtml += "<li><input id='btn17' type='button'value='Select' onmouseup='return checkorUncheck(ABC)' ><input type='checkbox' DISABLED name='ABC' id='ABC' value='YES' class='checkclass'  />" + getI18nLabel("LABEL_COUGH") + "</li>";
    checkorUncheck(ABC), checkorUncheck('ABC'),checkorUncheck(''ABC'') everything returns error. Can any one help me.

  2. #2
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27
    onmouseup='return checkorUncheck(ABC);'

    i think semicolon is missing..i am not sure

  3. #3
    Join Date
    Mar 2012
    Posts
    202
    Code:
    getElementById(id)
    and

    Code:
    onmouseup="checkorUncheck('ABC')"

  4. #4
    Join Date
    Oct 2011
    Posts
    19
    No , It is not working, as i cant give a double quote inside that.

    onmouseup="checkorUncheck('ABC')" is error.

    and if i give onmouseup='checkorUncheck('ABC')' it returns syntax error.

  5. #5
    Join Date
    Jan 2011
    Posts
    117
    Code:
     lHtml += "<li>"+
    "<input id=btn17 type=button value=Select onclick='checkorUncheck(\'ABC\')'>"+
    "<input type=checkbox id=ABC value=YES class=checkclass disabled>" + 
    getI18nLabel("LABEL_COUGH") + 
    "</li>";

  6. #6
    Join Date
    Jan 2011
    Posts
    117
    Code:
    if( !document.getElementById(id).checked )
    	{
    	document.getElementById(id).checked = true;
    	}
    	else
    	{
    	document.getElementById(id).checked = false;
    	}

  7. #7
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    With a not disabled check box it could be work better !

  8. #8
    Join Date
    Oct 2011
    Posts
    19
    Error: syntax error
    Source File: file:///.../index.html
    Line: 1, Column: 15
    Source Code:
    checkorUncheck(

    used the same
    Code:
    onclick='checkorUncheck(\'ABC\')'
    Code:
    function checkorUncheck(id)
    {
    if( !document.getElementById(id).checked )
    	{
    	document.getElementById(id).checked = true;
    	}
    	else
    	{
    	document.getElementById(id).checked = false;
    	}
    
    }

  9. #9
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264

    Watch your code !

    Code:
    <input type='checkbox' DISABLED name='ABC' id='ABC' value='YES' class='checkclass'  />

  10. #10
    Join Date
    Oct 2011
    Posts
    19
    No, i 've removed that. Still not working. Error console says some syntax error.
    I just tried with a new fresh code too.

  11. #11
    Join Date
    Mar 2012
    Posts
    202
    Sorry, missed the fact it is already being displayed in a variable. Other guy missed the fact that "\" doesn't escape HTML quotes. Try this:

    Code:
    <input id=btn17 type=button value=Select onclick='checkorUncheck(\"ABC\")'>

  12. #12
    Join Date
    Oct 2011
    Posts
    19

    Thumbs up

    Yeah.. It works

    Thank You Gray1989

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles