I am trying to figure out if there is already a function to do the following or how would I write a new one
if the page is editable, i build a table with text boxes in it.
<td><input type="text" id="blah" ... > </td>
otherwide:
<td id="blah">Sometext</td>
and then I build another table based on values from this table.
To get the value of the input box in jquery
i do:
$('#blah').val()
otherwise
$('#blah').text()
I want to write a function that based on the flag (isEditable) return the elements .val or .text
for example
jquery.fn.getValue = function() {
if (isEditable){
return $(this).val()
}
else {
return $(this).text()
}
}
and then I would be able to do:
$('#blah').getValue()
and I wouldn’t care whether its a cell or input box
You were basically already there: