How can I use input Box ID from PHP to JavaScript?

后端 未结 3 2091
滥情空心
滥情空心 2021-01-29 03:27

My JavaScript function works fine, but I have problems getting different ids from the PHP input box.

JavaScript

window.onload = function()
{   
new JsD         


        
相关标签:
3条回答
  • 2021-01-29 03:37

    It's most likely with JsDatePick widget. Its target parameter takes a single ID of an element, therefore you'd have to wrap the JS code in a loop and initiate a separate instance of the widget for each field ID.

    Assuming your input field indexing starts with 1:

    window.onload = function()
    {   
        var i = <?=$totalNumberOfInputs;?>
    
        for(j=1;j<=i;j++) {  
            new JsDatePick({
                useMode:2,
                target:"inputField" + j, //HERE I WOULD LIKE TO PASS DIFFERENT ID ex. "inputField1" + j
                dateFormat:"%Y-%M-%d",
                yearsRange:[1978,2120],
                limitToToday:false,
                cellColorScheme:"beige",
                imgPath:"main/img/",
                weekStartDay:1
            });
        }
    }
    

    You don't need to put the + sign to concatenate strings within double quotes (it's dot, by the way).

    0 讨论(0)
  • 2021-01-29 03:38
     //this is doesn't work 
    echo "<input type=\"text\" class='textboxsize' id= \"inputField$k\" name=\"start_date[]\" value=\"$start_date\" />";
    

    just remove that + sign.

    0 讨论(0)
  • 2021-01-29 03:42

    Change:

    id= \"inputField+$k\" name=...
    

    To:

    id=\"inputfield$k\" name=...
    

    What is screwing it up is the "+" sign. PHP uses "." to concatenate strings. ECHO out $k properly and you shouldn't have any trouble

    0 讨论(0)
提交回复
热议问题