ake the attached application and modify the second function so that if the user enters ANY name , for example Lawrence Michael Wolk into the input box next to the second function, the span output will be L.Michael.W. So if the name were instead Michael William Jackson, the output will be M.Wiiliam.J. (See output png attachments)
HTML/JAVASCRIPT
Take the attached application and modify the second function so that if the
user enters ANY name , for example Lawrence Michael Wolk into the input box next to the second function, the span output will be L.Michael.W.
So if the name were instead Michael William Jackson, the output will be M.Wiiliam.J.
(See output png attachments)
CISC_2350_CH_8_pp300_converter_asplithw.html
<html> <head> <script src="split.js" defer></script> </head> <body> <h1>Name Converter</h1> <p>Type your name:</p> <div> <input id="name" type="text" size="24" /> </br> <span id ="span1">second output goes here</span></br> <button id="but0">Convert to last, First</button> </br></br> <button id="buta"> Convert From Name MI. Lname to FI.MI.LI.</button></br> <input id ="name1" type ="text" size ="24"/> <span id= "span2">Third output goes here</span> </div> </body> </html>
split.js
onja = document.getElementById("but0");
onja.onclick=convertName;
onjb = document.getElementById("buta");
onjb.onclick=fnli;
function convertName() {
var input = document.getElementById("name");
var name = input.value;
var spaceIndex = name.indexOf(" ");
var firstName = name.substring(0, spaceIndex);
var lastName = name.substring(spaceIndex + 1);
/* lastName = lastName.toUpperCase();*/
var firstInitial = firstName.charAt(0);
input.value = lastName + ", " + firstInitial;
var s = " ";
objspan = document.getElementById("span1");
for ( var k= 0; k < firstName.length ; k++) {
if (k % 2 == 0) {
var position = firstName.length - k -1 ;
var smid = firstName.charAt(position);
s = s + smid;
}
}
var s1 = " ";
for ( var k= 0; k < lastName.length ; k++) {
if (k % 2 == 0) {
var position = lastName.length - k -1 ;
var s1mid = lastName.charAt(position);
s1 = s1 + s1mid;
}
}
objspan.innerHTML = s+ s1 ;
}
function fnli() {
var input = document.getElementById("name1");
var name = input.value;
var spaceIndex = name.indexOf(" ");
var firstName = name.substring(0, spaceIndex);
var lastName = name.substring(spaceIndex + 4);
var p1 = name.substring(spaceIndex+1,spaceIndex+2);
st = firstName.substring(0,1);
stm = p1;
st1 = lastName.substring(0,1);
stf = st + " ." + stm +"." +st1+"." ;
spanp = document.getElementById("span2");
spanp.innerHTML = stf;
}
Step by step
Solved in 2 steps