Reputation: 3
I am attempting to place the selected image file number (from a slideshow) into a form field with the onClick trigger but I get the console message Uncaught TypeError: Property 'value' of object # is not a function.
My function is;
function ifExistsWrite(str) {
var re = new RegExp('\"', 'gi');
var newstr = str.replace(re, '"');
if (newstr != "")
document.write(newstr + "<br>");
}
function fileNumber() {
document.getElementById(id = "item_number").value(ifExistsWrite("%CAPTIONTITLE%"));
}
And I am calling the value like this;
<form>
<input type="hidden" id="item_number" name="%CAPTIONTITLE%" value="">
<button type="submit" onclick="fileNumber();">Large</button>
</form>
I must confess that my 14 yr old son is better at javascript than me but he can't see the problem either.
Upvotes: 0
Views: 104
Reputation: 133403
console message Uncaught TypeError: Property 'value' of object # is not a function.
Use
document.getElementById("item_number").value= ifExistsWrite("%CAPTIONTITLE%");
Problems, value
is a property.
Additionally, You should return some value
function ifExistsWrite(str) {
var re = new RegExp('\"', 'gi');
var newstr = str.replace(re, '"');
if (newstr != "")
document.write(newstr + "<br>");
//Retrun your value
return newstr;
}
Upvotes: 1