Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  60] [ 4]  / answers: 1 / hits: 91868  / 13 Years ago, mon, october 31, 2011, 12:00:00

Inside my html file I call a javascript function that takes two parameters, where the second parameter is the name of a file that should be saved.



<a id=record_button onclick=Recorder.record('audio', 'test.wav'); href=javascript:void(0); title=Record><img src=images/record.png width=24 height=24 alt=Record/></a>


I would like to make a dynamic variable that takes the value from a textfield and forward that as the second parameter (instead of test.wav), so the user can determine the name of the file.



<label for=filename>Filename</label>
<input name=filename type=text>


Thanks.


More From » html

 Answers
17

This is easier if you give your user input an id attribute:



<input name=filename id=filename type=text>


Now you can access the value in Javascript with:



document.getElementById('filename').value


Note that, if you aren't controlling the Recorder.record() method, you'll need to validate the user input first (at a minimum, to verify that they've entered something). I'd recommend moving this to a separate function, e.g.:



function recordToFilename() {
var input = document.getElementById('filename'),
fileName = input.value;
if (fileName) {
Recorder.record('audio', fileName);
} else {
alert('Please enter a filename!');
input.focus();
}
}


Then just use that function:



<a id=record_button onclick=recordToFilename(); href=javascript:void(0); title=Record><img src=images/record.png width=24 height=24 alt=Record/></a>


Working example: http://jsfiddle.net/nrabinowitz/GFpRy/


[#89361] Friday, October 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynnb

Total Points: 402
Total Questions: 96
Total Answers: 109

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
kaitlynnb questions
;