Solved

Help setting input value

Posted on 2011-03-20
2
309 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
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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
https://github.com/willowsystems/jSignature 11 52
Jquery GMAP3 Hierarchy 1 28
javascript comparing two dates 3 19
asp.net mvc5 6 17
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

810 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