?
Solved

Help setting input value

Posted on 2011-03-20
2
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 35178057
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 2000 total points
ID: 35179242
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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

752 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