使用javascript创建ID

时间:2015-04-24 06:52:31

标签: javascript

我想通过获取他们的第一个字母&来创建三个不同文本框值的staffid。添加自动增量编号atlast。

例如" staffname"," gender"," names"结果staffid:sgd01&我希望在staffid文本框被禁用时自动显示在staff id文本框中。以下是代码:

<input name="staffname" id="staffname" size="30" type="text" value placeholder=" Staff Name" onkeyup="quick()" class="formTxtInput">

脚本

function quick() {   

    var gender = document.getElementById('gender').value;
    var staffname = document.getElementById('staffname');
    var desg = document.getElementById('desg').value;

    var gen = gender.charAt(0);
    var sn = staffname.charAt(0);
    var dg = desg.charAt(0);

    var val = gen + sn + dg;
    document.getElementById('staffid').value = val;
}

2 个答案:

答案 0 :(得分:0)

var staffname缺少.value。它应该是

var staffname = document.getElementById('staffname').value;

此外,您需要在3个输入框中的每个输入框上调用您的函数,以便可以处理更新的值

以下是工作示例:http://jsbin.com/vobikejejo/1/

希望这会有所帮助:)

答案 1 :(得分:0)

您可以尝试更新您的功能,如下所示:

    private void IlPanelOnLoad()
    {
        ...

        var plotCube = GetPlotCube();
        if (plotCube != null)
        {
            plotCube.MouseWheel += OnPlotCubeMouseWheelEvent;
        }
    }


    #region MouseWheel Zoom

    const float scaleFactor = 0.05f;  // 5% scaling, Adjust this to get faster/slower scaling
    const float WHEEL_DELTA = 120.0f; // One mouse wheel notch

    void OnPlotCubeMouseWheelEvent(object sender, ILMouseEventArgs mea)
    {
        if (mea.Clicks == 0) // Only when no buttons pressed at the same time
        {
            var plotCube = sender as ILPlotCube;
            if (plotCube != null)
            {
                // + or - a scaleFactor change per wheel mouse notch
                float zoomFactor = 1 - ((float)mea.Delta) / WHEEL_DELTA * scaleFactor;
                ILLimits ilLimits = plotCube.Limits;
                ApplyScaleFactor(zoomFactor, ilLimits);
                ilPanel.Refresh();
            }
        }
        mea.Cancel = true; // Stop mouse wheel event default behaviour
    }

    private void ApplyScaleFactor(float zoomFactor, ILLimits ilLimits)
    {
        // delta here is nothing to do with wheel mouse delta
        float delta = ilLimits.WidthF * zoomFactor / 2f;
        ilLimits.XMin = ilLimits.CenterF.X - delta;
        ilLimits.XMax = ilLimits.CenterF.X + delta;
        delta = ilLimits.HeightF * zoomFactor / 2f;
        ilLimits.YMin = ilLimits.CenterF.Y - delta;
        ilLimits.YMax = ilLimits.CenterF.Y + delta;
    }

    private void ApplyScaleFactorHasWhitePatches(float zoomFactor, ILLimits ilLimits)
    {
        ilLimits.Update(ilLimits.CenterF, zoomFactor);
    }

    #endregion MouseWheel Zoom

默认情况下没有值,因此无效。尝试设置默认值。

<script>
 var num=01;
 function quick() { 
  num+=1;
  var gender = document.getElementById('gender').value;
  var staffname = document.getElementById('staffname').value;
  var desg = document.getElementById('desg').value;
  var gen = gender.charAt(0);
  var sn = staffname.charAt(0);
  var dg = desg.charAt(0);

  var val = gen + sn + dg + num;
  document.getElementById('staffid').value = val;
}

你可以在这里查看演示1