Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
This guy wants to set or hardcode a value in a formfield in sharepoint. More clear than water. Does anyone have a solution about this? Regards Pete –  user20979 Nov 22 '13 at 19:37
add comment

6 Answers

you might added the extra curly brace to build the MAIN() like the sample below

<script type="text/javascript">
    $(document).ready(function () {

        //program logic


    });

           } // the culprit extra brace

</script>

http://social.msdn.microsoft.com/Forums/sk/sharepoint2010general/thread/a9fb3163-109c-4309-96d2-4f2f19e6824a

Hope it helps.

share|improve this answer
add comment

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.

share|improve this answer
    
As you could see, his jquery has input in the selector –  Colin Feb 2 '12 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 '12 at 0:58
add comment

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 *
share|improve this answer
add comment

Try this instead:

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

I really wished to understand what has been asked in this question.
Having too long for a comment misunderstandings I hope the question would be reformulated into more comprehensible one...

The markup of an element (or node but not "tag") does not look to me as part of list form (are there forms for a list at all?) but rather of item form.

The jQuery expression:

$("input[title='Name']").val("Bob")

sets the known value "Bob" to Sharepoint field of node with attribute 'Title="Name"', while the expression:

var ele = $("input[title='Name']").val();

gets that value into variable ele.
One more problem is that cited element doesn't contain any attribute Title?!

So, it is not clear to me what, from where to where the questioner is asking to set or to get? and what?

share|improve this answer
add comment

Try this:
Using Sharepoint Designer 2010: modify form.
Wrap textbox by div with special ID.
Such as ID="myDiv"

This must help you to find needed textbox!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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