0

I did have code that did work, but I needed to modify it

http://jsfiddle.net/bthorn/xbs5c41b

THEN I was told that I needed to change from input to label (span)

NOW this code does not work even though I changed from

http://jsfiddle.net/bthorn/xbs5c41b/1/

.find("input")

to

.find("span")

Notice the code line that I commented out

 function setDateTimeOn(elm) {
        var formattedDate = GetCurrentDateTime(); //get formatted date
        $(elm) //clicked button
            .parent("td") // container td
            .next() // next td
            //.find("input") // find child input
            .find("span")
            .val(formattedDate); //set date
    }

HTML

<table>
<tr>
    <td style="width:5px;">
        <input type="button" id="GridView1__ctl2_AddButton0" name="GridView1:_ctl2:AddButton0" value="On" class="btn-blue" onclick="setDateTimeOn(this)">
    </td>
    <td style="width:150px;">
       <!-- <input id="GridView1__ctl2_txtStormTimeOn" type="text" name="GridView1:_ctl2:txtStormTimeOn" value="">-->
        <span id="GridView1__ctl2_lblStormTimeOn"></span> 
    </td>
</tr>

Can ".find() not work on span?

user2019037
  • 764
  • 1
  • 7
  • 14
  • possible duplicate of [how to set a value for a span using JQuery](http://stackoverflow.com/questions/1491743/how-to-set-a-value-for-a-span-using-jquery) – Jeff Noel Sep 22 '15 at 17:17

2 Answers2

3

The find method works.

The problem with your code is the val one, that doesn't, since it tries to find a value property on the element, and although the HTMLInputElement has one, the HTMLSpanElement doesn't.

You must change it to use the text method.

/* (...) */
.find("span")
.text(formattedDate); // set date

And here is your fiddle updated.

Buzinas
  • 11,597
  • 2
  • 36
  • 58
0

The span element is not neasted with your input, so you must use parent() to reach it's scope. And plus, you don't use val with span, like div you must use text() or html() instead:

function setDateTimeOn(elm) {
    var formattedDate = GetCurrentDateTime(); //get formatted date
    $(elm) //clicked button
        .parent("td") // container td
        .next() // next td
        //.find("input") // find child input
         .parent().find("span")
        .html(formattedDate); //set date
}
Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43
  • I am not familiar with .parent().find("span") .html(formattedDate); //set date It may work but I already tested the other code and that works fine for me thx though –  Sep 22 '15 at 17:25