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”, “”);
});
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>
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)