edwind
edwind

Reputation: 3

How to enter variable content into form field

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

Answers (1)

Satpal
Satpal

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, '&quot;');
    if (newstr != "")
        document.write(newstr + "<br>");

    //Retrun your value
    return newstr;
}

Upvotes: 1

Related Questions