简体   繁体   中英

How do you include a javascript variable in a hyperlink?

I have pretty simple code

<input type="hidden" name=passtophp value=variable>

The variable is created in javascript in the head of the document. Unfortunately when I put in the variable name it is captured as a string and passed through instead of the variable's actual value. How can I pass through the variable's value? Thank you!!

var myVariable = 'myValue';
document.getElementById('passtophp').value = myVariable ;

Ensure you specifty an ID on the hidden field though.

<input type="hidden" name='passtophp' id='passtophp' />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM