/    Sign up×
Community /Pin to ProfileBookmark

Inconsistent recognition of id

I am an admitted novice, but this looks pretty straight forward to me.

I am attempting to replace text on two controls…..one works the other doesn’t. The one that doesn’t says the value I am after is undefined.

Here’s my javascript

[CODE]$(function () {
console.log(“Trying GigDate”);
document.[B]getElementById(“GigDate”)[/B].value = document.getElementById(“GigDate”).value.replace(” 12:00:00 AM”, “”);
console.log(“Trying ph”);
console.log(document.getElementById(“ph”).value)
document.[B]getElementById(“ph”)[/B].value = document.getElementById(“ph”).value.replace(” 12:00:00 AM”, “”);
});[/CODE]

Here is the relevant rendered HTML

[code=html]<script src=”/CustomScripts/GigEdit.js”></script>
<div class=”panel”>
<div class=”panel-heading”>
<h3 [B]id=”ph”[/B]>9/5/2017 12:00:00 AM</h3>
</div>
<form action=”/Gigs/Edit/2″ enctype=”multipart/form-data” method=”post”> <div class=”panel-body”>
<input data-val=”true” data-val-number=”The field GigId must be a number.” data-val-required=”The GigId field is required.” id=”GigId” name=”GigId” type=”hidden” value=”2″ />
<input data-val=”true” data-val-number=”The field BandId must be a number.” data-val-required=”The BandId field is required.” id=”BandId” name=”BandId” type=”hidden” value=”1″ />

<div class=”form-group”>
<label class=”col-lg-3 control-label”>Date</label>
<input class=”form-control” data-val=”true” data-val-date=”The field GigDate must be a date.” data-val-required=”The GigDate field is required.” [B]id=”GigDate”[/B] name=”GigDate” type=”text” value=”9/5/2017 12:00:00 AM” />
<span class=”field-validation-valid” data-valmsg-for=”GigDate” data-valmsg-replace=”true”></span>
</div>
[/code]

Here is the output from the console:

Trying GigDate
GigEdit.js:4 Trying ph
GigEdit.js:5 undefined
GigEdit.js:6 Uncaught TypeError: Cannot read property ‘replace’ of undefined
at HTMLDocument.<anonymous> (GigEdit.js:6)
at fire (jquery-1.10.2.js:3062)
at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
at Function.ready (jquery-1.10.2.js:447)
at HTMLDocument.completed (jquery-1.10.2.js:118)

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ebickauthorJul 17.2017 — P.S. The Bold tags you see in the HTML were me trying to highlight where the issue was....they are NOT in the rendered HTML and I can't seem to find the button to edit my post.
Copy linkTweet thisAlerts:
@rootJul 17.2017 — JQuery goes in the JavaScript Frameworks forum not the JavaScript forum ?
×

Success!

Help @ebick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...