我想让表单中的文本框的值始终为大写,我使用此代码
<tr>
<td width=70>No. Polisi</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="nopol" type="text" name="nopol" maxlength="10" size="26" style="text-transform:uppercase" /> </td>
<td width=1></td>
</tr>
但是当我点击提交按钮时,我给出了大写文本代码的文本框。我从该文本框中获取的数据将更改为小写(在我的数据库中)
答案 0 :(得分:2)
在前端,你使用css来定位输入类型文本,并使用text-transform为大写:下面是一个工作小提琴。
input[type="text"]{
text-transform : uppercase
}
<form action="">
<input type="text" id="nopol" type="text" name="nopol" maxlength="10" size="26">
<input type="submit" name="submit" formmethod="POST">
</form>
然后在您的服务器端使用php的strtoupper()
函数将文本转换为大写
<?php
if(isset($_POST['submit'])){
$nopol = strtoupper($_POST['nopol']);
echo $nopol;
}
?>
答案 1 :(得分:1)
text-transform:大写是css属性。它只影响用户显示。要将其转换为大写,请使用javascript或jquery
<table>
<tr>
<td width=70>No. Polisi</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="nopol" type="text" name="nopol" maxlength="10" size="26" style="text-transform:uppercase" /> </td>
<td width=1></td>
</tr>
<tr>
<td>
<input type="submit" value="submit"/ onclick="getValue()">
</td>
</tr>
</table>
编写javascript函数
function getValue() {
alert(document.getElementById('nopol').value.toUpperCase());
}
答案 2 :(得分:0)
添加您的HTML
<input id="nopol" type="text" name="nopol" maxlength="10" size="26" style="text-transform:uppercase" onkeydown="upperCaseF(this)"/>
添加您的javascript
function upperCaseF(a){
setTimeout(function(){
a.value = a.value.toUpperCase();
}, 1);
}
答案 3 :(得分:0)
使用
int[SIZE]
仅进行视觉转换。您的实际输入将保留您输入的格式。将数据发布到服务器后,必须将其转换为UPPER才能将其保存为大写。