简体   繁体   中英

how to get php inputbox name variable into javascript?

please look at this code and help where is the error,

foreach($FormVars["Level"] as $key=>$value)
{
 $i=1;

 echo('<tr><td align="center" >'.$key.'</td>
 <td><INPUT Type="text" size="40" name="Designation_Level['.$key.']" value="'.$value.'" 

 onKeyDown="textCounter(document.FM_OrgDesignations.Designation_Level[<?php    
 echo'.$key.';?>],document.FM_OrgDesignations.remLen[<?php echo $i;?>],50)"

 onKeyUp="textCounter(document.FM_OrgDesignations.Designation_Level[<?php     
 echo'.$key.';?>],document.FM_OrgDesignations.remLen[<?php echo $i?;>],50)"/>

<input readonly type="text" name="remLen[<?php echo $i;?>]" style="border:0px; border-color:#F1EFFC; background-color:#FFFFFF;"></td></tr>');
$i++;

}

In the above code, i want to pass this inputbox name for textcounter() . How I can take that php variable in javascript? Also how I can change the readonly inputbox name in every loop.?

I want to call this textcounter() for all inputbox field.

Do it like this (snippet):

_Level["'.$key.'"]

Don't forget to quote the value in Javascript! ;)

I think you're looking for something like:

/*    $FormVars = array (
        'Level' => array (
            'first' => 'this is first',
            'second' => 'this is second',
            'third' => 'this is thirs',
        ),
    ); */

    $i = 1;
    foreach($FormVars["Level"] as $key=>$value)
    {

    echo '<tr><td align="center" >'.$key.'</td>

    <td><INPUT Type="text" size="40" name="Designation_Level['.$key.']" value="'.$value.'" 
    onKeyDown="textCounter(document.FM_OrgDesignations.Designation_Level[\'' . $key . '\'],document.FM_OrgDesignations.remLen[<?php echo $i;?>],50)"

    onKeyUp="textCounter(document.FM_OrgDesignations.Designation_Level[\'' . $key . '\'],document.FM_OrgDesignations.remLen[<?php echo $i?;>],50)"/>

    <input readonly type="text" name="remLen[\'' . $i . '\']" style="border:0px; border-color:#F1EFFC; background-color:#FFFFFF;"></td></tr>';

    $i++;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM