Malachi
Malachi

Reputation: 977

Change submit button value depending on id of table

I have the following code:

<table cellspacing="0" cellpadding="0" border="0" width="100%" id="carttable">
<tbody><tr id="carttableheader">
<td>blah</td><td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr id="carttablerow0" class="uir-list-row-tr uir-list-row-even">
<td>blah</td><td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td>blah</td><td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td class="extcartborder">blah</td>
<td class="extcartborder">blah</td>
<td class="extcartbordershaded">blah</td>
</tr>
<tr>
<td colspan="4" class="extcartborder">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr>
<td class="extcart">&nbsp;</td>
<td class="extcart"><table>
<tbody><tr><td class="textbold" colspan="2">blahblah</td></tr>
            <tr>
                <td>blah</td>
                <td>blah</td>
            </tr>
            <tr>
                <td>blah</td>
                <td>blah</td>
            </tr>


<tr><td>&nbsp;</td><td><span id="tbl_submitter"><input type="submit" name="submitter" id="submitter" value="Submit" style="" class="bgbutton"></span></td></tr>
</tbody></table></td>
 etc. etc..

The button at the end now has the value 'Submit' and needs to change to 'Other Text'. I know the table above is old fashioned, ugly, [fill in the blank], but I can't get around that.

I tried this:

$('#carttable').closest('#submitter').prop('value', 'Other Text');

But it didn't change anything. I looked in firebug's script tab to see what the value was, and it was 'Submit', so that was good, but it didn't replace this. (I know I can do $("#submitter").attr('value', 'Other Text');, but this is also called on other pages, and since #submitter exists there as well, but with a different set up, it would mess it up.. whole story). Anyway.. why doesn't the call work?

Edit: I have jquery loaded via https://code.jquery.com/jquery-latest.js. I know it's not the latest, but 1.11 I believe.. but still, .prop works.

Upvotes: 0

Views: 150

Answers (1)

sebnukem
sebnukem

Reputation: 8333

The following selector should also work for you:

$('#carttable #submitter').prop('value','Other Text');

(see http://api.jquery.com/descendant-selector/)

Upvotes: 1

Related Questions