开发者

JS function hidden element value

I have a hidden element:

<input id="enableStat" type="hidden" value="<!--#echo var="enableStat"-->" />

I am using this variable to flag if certain feilds were enabled or disabled.

In JS:

    if(somecondition==false) 
    {
        document.getElementById('enableStat').value = 0;
        //some other statements
    }  
    else
    {
        document.getElementById('enableStat').value = 1;
        //some other statements
    } 

I then check for this variale in my CGI:

SSPEC_RESOURCE_ROOTVAR("enableStat", sEnable, PTR16, "%s"),       
static char sEnable[2];
if(!strncmp(sEnable, "1", 1))
     //do something

Now, what I see is that the value in senable is always 1 no matter what. The if-else statements in JS are executed properly.

To add here, the statements:

document.getElementById('enableStat').value = 0; 
document.getElementById('enableStat').value = 1;

If I make my question more clearer: I want to create a variable/element in JS which I can use in CGI. How can I do开发者_如何转开发 this. In the above code, there seems to be some syntax mistake or variable name etc.


If you're coding in C/C++ then you should be using strncmp to compare strings. strncpy copies the string and returns the address of the destination, which is an address and therefore won't be 0, so will always evaluate to true...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜