0

I have this code and want to pass the input to my GoLargeSearch function when I click the image.

<div id="s4-searcharea-large">
    <input accessKey="S" onkeydown="CoreInvoke('LargeSearchKeyDownGoSearch', event)" id="txtLargeSearchTerm" runat="server" class="ms-sharepointsearchtext" title="Enter search words" value="" maxLength="255" size="25" type="text" name="SearchString" /> 
    <div class="ms-searchimage">
        <span style="position: relative; width: 27px; display: inline-block; height: 27px; overflow: hidden" class="s4-clust">
            <a style="width: 27px; display: inline-block; height: 27px" id="onetIDGoSearchLarge" title="Search" onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm'))" href="javascript:">
                <img style="border-bottom: 0px; position: absolute; border-left: 0px; border-top: 0px; border-right: 0px;" alt="Search" src="/_layouts/GP_Custom/images/largesearch.png" />
            </a>
        </span>
    </div>
</div>

How do I get the value of the input to pass it to GoLargeSearch? This doesn't seem to work:

onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm'))"

2 Answers 2

3

You're missing the part where you get the value of that element:

onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm').value)"
Sign up to request clarification or add additional context in comments.

4 Comments

What happens if you just alert the value of that element? alert(document.getElementById('txtLargeSearchTerm').value)
onclick=alert(document.getElementById('txtLargeSearchTerm').value) also gives me an object required error at runtime
This gives me a 'System' is undefined error: onclick="$get(<%=txtLargeSearchTerm %>)"
Something somewhere else is conflicting with this. I can't say where as I obviously don't know about your code to figure it out. But the answer above will work once you can sort out what is causing this new issue.
0

This works!

function GoLargeSearch (obj) { alert(obj.value); }

But it's very ugly code =/ Aren't you able to use JQuery?

2 Comments

No I'm getting System is undefined error. . . . Values are being passed to my function just fine. For example if I did : onclick=GoLargeSearch("Hello") then Hello would be passed to my function. What i'm having trouble with is getting the value from my textbox input
Also i'm using javascript, HTML, visual studio 2010. And this is for a custom webpart in Sharepoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.