I have a textfield in sharepoint list form and I want to set the value using jquery or javascript below is the tag:

<asp:TextBox runat="server" id="ff47{$Pos}" text="{@Name}" __designer:bind="{ddwrt:DataBind('i',concat('ff47',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Name')}" />

I am using this to set var ele = $("input[title='Name']").val("Bob"); but it is not setting the value, any suggestions?

link|improve this question

feedback

3 Answers

Could you post the exact rendered Html? I ask this because usually id and name attribute value contain a crappy generated string. You could try a wildcard in your selector:

var ele = $("input[title='*Name']").val("Bob"); // notice the *
link|improve this answer
feedback

Try this instead:

$("input[value='Name']").val("Bob");
link|improve this answer
Hi James,i tried it but it is not working – spStacker Feb 2 at 21:14
feedback

You need to Inspect that particular textbox with FireBug or IE Developer tools. If I am right the asp:Textbox is internally converted to an input control which will have a unique attibute. You can use this attribute to pickup the input with JavaScript/jQuery and set the value.

From what I can gather, you are setting the id and the text dynamically by using placeholder variables. I would inspect these two attributes and reference the input field by using one of them.

link|improve this answer
As you could see, his jquery has input in the selector – Colin Feb 2 at 23:59
True. But the attributes of the input are being generated dynamically and they need to be picked up correctly with jQuery. – Vardhaman Deshpande Feb 3 at 0:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.