在提交表单时将输入文本转换为小写 [英] Convert input text to lowercase on submitting a form

查看:91
本文介绍了在提交表单时将输入文本转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中有一个文本字段提供了一个提交按钮。点击提交按钮后,它会从第一个php页面重定向到第二个php页面。
index.php

 < form action =submit.phpmethod =get> 

< input type =textname =searchid =search/>
< input type =submitvalue =submitonclick =convert()/>
< / form

< script type =text / javascript>
函数convert()
{
alert(hi);
var str;
str = document.getElementById(search)。value;
document.writeln(str.toLowerCase());
}
< / script>

提交表单时,我希望URL变得像submit.php?search = text p>

我希望这个文本是小写的,尽管输入的文本是大写的。
请引导我如何使这个文本小写,我正在使用上面的脚本将其转换为小写。但它没有在URL中以小写字母转换文本。



请指导我解决这个问题。

解决方案

>

 < form action =submit.phpmethod =getid =form1> 



<2>使您的< input> 键入为按钮。原因是因为我们想要确保 convert()函数先被执行,然后我们将提交表单。

 < input type =buttonvalue =submitonclick =convert()/> 

3)最终javascript转换为:

函数convert()
{
alert(hi);
var str;
str = document.getElementById(search);
str.value =(str.value.toLowerCase());
//获取表单ID并提交
var form = document.getElementById(form1);
form.submit();
}

小提琴


I have a form in which there is one text field is provided with a submit button.On clicking submit button,it redirects to second php page from first php page. index.php

<form action="submit.php" method="get">

<input type="text" name="search" id="search" />
<input type="submit" value="submit" onclick="convert()" />
</form 

<script type="text/javascript">
function convert() 
{
    alert("hi");
    var str ;
    str = document.getElementById("search").value;
    document.writeln(str.toLowerCase());
}
</script>

On submitting the form,i want the url to become like submit.php?search=text

I want this text to be in lower case,although if text entered is uppercase. Please guide me how to make this text lower case,I am using the above script for converting it to lower case.But its not converting the text in lower case in URL.

Please guide me on this..

解决方案

You can do this only using javascript with a few extra stuff:

1) Give your <form> an id

<form action="submit.php" method="get" id="form1">

2) Make your <input> type as button. The reason for this is because we want to make sure the convert() function is executed first, and after that we will submit the form.

<input type="button" value="submit" onclick="convert()" />

3) Finally javascript to:

function convert() 
{
    alert("hi");
    var str ;
    str = document.getElementById("search");
    str.value = (str.value.toLowerCase());
    //get the form id and submit it
    var form = document.getElementById("form1");
    form.submit();
}

Fiddle

这篇关于在提交表单时将输入文本转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆