javascript - How do I display user input into my story -


i trying create story interjects users input answers text boxes , radio buttons. yet having trouble display. displays until "+transport+". have far:

function story()         {              //collect users input data              var transport = "";             var name = document.getelementsbyname("name")[0].value             var title = document.getelementsbyname("title")[0].value             var noun = document.getelementsbyname("noun")[0].value             var num1 = document.getelementsbyname("num1")[0].value             var num2 = document.getelementsbyname("num2")[0].value             var travelmeasure = document.getelementsbyname("measuretravel")[0].value              //determine mode of transportation chosen             if (document.getelementsbyname("transport")[0].checked)             {                 transport = spaceship;             }             else if (document.getelementsbyname("transport")[1].checked)             {                 transport = ducatti;             }             else if (document.getelementsbyname("transport")[2].checked)             {                 transport = ferrari;             }             else if (document.getelementsbyname("transport")[3].checked)             {                 transport = jet;             }             else if (document.getelementsbyname("transport")[4].checked)             {                 transport = train;             }               //determine measure of travel chosen             if (document.getelementsbyname("measuretravel")[0].checked)             {                 miles = "+num1+" + "+num2+" * 1.60934                 measuretravel = miles;             }             else if (document.getelementsbyname("measuretravel")[1].checked)             {                 measuretravel = kms;             }               //write new html page display story              document.writeln("<h1>"+title+"</h1>");              document.writeln("<p>once upon time,</p>");              document.writeln("<p>"+name+" trying make way "+noun+" in "+transport+".</p>");              document.writeln("<p>unfortunately "+name+" didn't realise how far away "+houn+" was.</p>");              document.writeln("<p>the assumption "+num1+" "+measuretravel+" when turned out "+num2+" "+measuretravel+".</p>");              document.writeln("<p>thankfully "+name+" likes travel.</p>");              document.writeln("<p>the end</p>");          } 

var travelmeasure = document.getelementsbyname("measureravel").value 

should

var measuretravel = document.getelementsbyname("measuretravel")[0].value 

note: 't' missing in 'travel', there no index [0], , transposed measure & travel in variable name between assignation , use

(and, right, needed set of eyes)


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -