admin管理员组

文章数量:1278976

I am trying to change a textbox value. am trying following javascript but in both the alerts am getting image only. ie. $('#FileName').val = "testimage.jpg"; is not changing the text box field value.

<x:input type="textbox" id="FileName"
width="210px" value=""/>

if ($("#FileName").val() == "image") {
    alert($("#FileName").val())
    $('#FileName').val = "testimage.jpg";
    alert($("#FileName").val())
 } 

I am trying to change a textbox value. am trying following javascript but in both the alerts am getting image only. ie. $('#FileName').val = "testimage.jpg"; is not changing the text box field value.

<x:input type="textbox" id="FileName"
width="210px" value=""/>

if ($("#FileName").val() == "image") {
    alert($("#FileName").val())
    $('#FileName').val = "testimage.jpg";
    alert($("#FileName").val())
 } 
Share Improve this question asked Mar 20, 2013 at 6:50 RomiRomi 4,93128 gold badges83 silver badges114 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

you have used jquery

try $('#FileName').val("testimage.jpg");

and using javascript document.getElementById('')

document.getElementById('FileName').value = "testimage.jpg";

you should try this

if ($("#FileName").val() == "image") {
    alert($("#FileName").val())
    $('#FileName').val("testimage.jpg");
    alert($("#FileName").val())
}

val is a method, not a property, so:

$('#FileName').val("testimage.jpg";)

本文标签: How to change textbox value using javascriptStack Overflow