[英]javascript change onblur value
I have 2 selections and a textbox. 我有2个选择和一个文本框。 I want to change the onBlur value of the textbox when i select one of the selections.
当我选择选项之一时,我想更改文本框的onBlur值。 Here is my code:
这是我的代码:
function changeBlurValue(){
$selection = document.getElementById("searchtype")
$onblurvalue= document.getElementById("searchbox")
if ($selection.value="location"){
$onblurvalue.value="Enter a location name";
};
}
//html // HTML
<select name= "searchtype" id="searchtype" onclick="changeBlurValue()">
<option value="gymname">Gym Name
<option value="location">Location
</select><br><br>
<input name="searchterm" type="text" size="39" style="color:#888;" id="searchbox"
value="Enter a gym name" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
The problem is that the selection is permanent at "Location" and I can't change it to "Gym Name" 问题是选择在“位置”是永久的,我无法将其更改为“健身房名称”
Thanks for the help. 谢谢您的帮助。
I would try using onChange
instead of onClick
for your select. 我会尝试使用
onChange
代替onClick
进行选择。
<select name= "searchtype" id="searchtype" onchange="changeBlurValue()">
Also close your <option>
tags, as such: 同时关闭您的
<option>
标记,例如:
<select name= "searchtype" id="searchtype" onchange="changeBlurValue()">
<option value="gymname">Gym Name</option>
<option value="location">Location</option>
</select>
The problem lies here: 问题出在这里:
if ($selection.value="location"){
You should change it to 您应该将其更改为
if ($selection.value=="location"){
because you are making a comparision. 因为您正在进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.