James Freeberg
James Freeberg

Reputation: 581

I Need A Javascript Code That Will Place The Word "Search" In An Empty DIV Value Tag Using The id=

I have no access to the html, I need JavaScript code that will add the word "Search" to the value="" that is blank for the input with id "ReportQuery".

How should I code it?

Here is the code below:

<div>
    <input name="data[Report][query]" type="text" class="input_firm" value="" onChange="this.form.submit();" onClick="if( this.value == &#039;Search&#039; ) { this.select(); }" id="ReportQuery" />
    <input type="submit" value="Search" />
</div>

Upvotes: 0

Views: 409

Answers (3)

jbabey
jbabey

Reputation: 46647

$('#ReportQuery').val('Search');

http://jsfiddle.net/L9YS4/

A good place to start for learning jQuery:

http://jqfundamentals.com/

Upvotes: 0

Horst Walter
Horst Walter

Reputation: 14081

See this article, it comes with many examples and details: http://www.javascript-coder.com/javascript-form/javascript-form-value.phtml

BTW, this is about the "direct" JS way, no jQuery involved, e.g.

 oFormObject = document.forms['myform_id'];
 oFormObject.elements["element_name"].value = 'Some Value';

Upvotes: 0

Toni Michel Caubet
Toni Michel Caubet

Reputation: 20163

if its a div

$('div#idDiv').text('search');

if its an input (because you comment .value :S)

$('input#idDiv').val('search');

Upvotes: 1

Related Questions