Solved

Help setting input value

Posted on 2011-03-20
2
307 Views
Last Modified: 2012-05-11
In the following code snipplet, I'm creating a "select" button. Clicking the btnSelect button, should set the value of the input field called input-value.

When I click on the button now, nothing happens. No error but now update to the input-value field either.

How can I update the input-value field when the btnSelect is pressed.


The input field looks like this:

<input id="input-value" name="input-value" type="text" value="">

Open in new window

$.ucm.emuseumSearch3(text, function(ucmResponse) {
						// draw the results to the page
						var resultHtml = "";
						var searchResults2 = ucmResponse.ResultSets['objectRS'];
						for (var rowIndex in searchResults2.rows) {
							var row = ucmResponse.getRow("objectRS", rowIndex);
							resultHtml = resultHtml + "<tr><td>" + row.id +
								"</td><td>" + row.title + "</td>" +
								"<td><button id='btnSelect' name='btnSelect' value='"+row.id+"' onclick='document.getElementById(\'input-value\').value=this.value'>Select</button></td></tr>\n";
						}
						$("#searchResults2 tbody").html(resultHtml);
						$("#searchResults2").show();
					});

Open in new window

0
Comment
Question by:greddin
2 Comments
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
please share the html code for btnSelect button, or try something like this

<input id="btnSelect" name="btnSelect" type="button" value="Select"/>


$("#btnSelect").bind("click", function(){
   $("#input-value").val("somevalue");
});

0
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
Comment Utility
Perhaps the nested inner quotes are a problem.
"<td><button id='btnSelect' name='btnSelect' value='"+row.id+"' onclick='document.getElementById(\"input-value\").value=this.value'>Select</button></td></tr>\n";

Open in new window

Why are you using an inline event handler (onclick attribute) anyway?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now