I currently have textfields in which I set a value, as soon as I press the change button this function gets triggered:
function change1(){
var myNewTitle = document.getElementById('myTextField1').value;
if( myNewTitle.length==0 ){
alert('Write Some real Text please.');
return;
}
document.getElementById("myLink").href="convert.php?var1=" + myNewTitle ;
var titles = document.getElementsByClassName('title1');
Array.prototype.forEach.call(titles,title => {
title.innerHTML = myNewTitle;
});
}
Here is an example of the textfield:
Voornaam: <h3 class="title1">Kevin</h3>
<input type="text" id="myTextField1" />
<input type="submit" id="byBtn" value="Change" onclick="change1()"/><br/>
Passing the value like this seems to work perfectly fine but the problem is I have some other textfields and more change functions. But how do I pass multiple values from multiple textfields like the one I just showed?
So let's say textfield 1 is attached to function change1, I have textfield 2 that's attached to almost the same function change 2. How do I make it so I pass another value from textfield 2 so that both values from textfield 1 and 2 get passed to the other page.
Edit: I've tried it like so but this does not work, but this is an idea of how I wish it would work.
function change1(){
var myNewTitle = document.getElementById('myTextField1').value;
if( myNewTitle.length==0 ){
alert('Write Some real Text please.');
return;
}
document.getElementById("myLink").href="convert.php?var1=" + myNewTitle +"&var2=" + myNewTitle2;
var titles = document.getElementsByClassName('title1');
Array.prototype.forEach.call(titles,title => {
title.innerHTML = myNewTitle;
});
}
function change2(){
var myNewTitle2 = document.getElementById('myTextField2').value;
if( myNewTitle.length==0 ){
alert('Write Some real Text please.');
return;
}
document.getElementById("myLink").href="convert.php?var1=" + myNewTitle +"&var2=" + myNewTitle2;
var titles = document.getElementsByClassName('title2');
Array.prototype.forEach.call(titles,title => {
title.innerHTML = myNewTitle2;
});
}