javascript - html form - getting value from selected radio button -
i have created form , looking data user entered. javascript have, far pulls in data. having issue pulling data of selected radio button. read articles , 'name' needs sames doesn't work , if give unique 'id's selecting 1 or other radio buttons doesn't work. can't use jquery
js
var mynodelist = document.getelementsbyname('cf'); var myarray = []; // empty array (var = 0; < mynodelist.length; i++) { if(i<4) ( i; < 3; i++) { var self = mynodelist[i].value; myarray.push(self); } else if(i==4) myarray.push(document.getelementbyid('status').value); else if(i==5) myarray.push(document.getelementbyid('subscribe').value); else if(i==6) myarray.push(document.getelementsbyname('support')[i]); else if(i==7) ( i; < mynodelist.length; i++) { var self = mynodelist[i].value; myarray.push(self); } } console.log(myarray)
html
<!doctype html> <html> <head> <title>contact me</title> <link rel="stylesheet" type="text/css" href="contactform_lab8.css"> </head> <body> <form id="contactus"> <fieldset> <label for="name">name:</label> <input id="name" type="text" name="cf" autofocus required> <label for="email">email:</label> <input id="email" type="email" name="cf" required> <label for="phone">phone:</label> <input id="phone" type="tel" name="cf" required> <label for="status">status: <select id="status" name="cf" required> <option value="client">client</option> <option value="partner">partner</option> <option value="vendor">vendor</option> </select> </label> <label for="subscribe"> <input id="subscribe" type="checkbox" name="cf" value="check" checked> send me newsletter</label> <label for="sales"> <label for="support"> <input id="sales" type="radio" name="slssupport" value="sales" checked>sales <input id="support" type="radio" name="slssupport" value="support">support </label> </label> <label for="msg">message:</label> <textarea id="msg" name="cf" rows="10" cols="30" required></textarea> </fieldset> <fieldset> <button type="submit">send</button> <button type="reset">reset</button> </fieldset> </form> <script src="contactform_lab8.js"></script> </body> </html>
id names unique , should not used twice in same page. can value checked radio buttons this:
var inputs = document.getelementsbytagname('input'); for(var = 0; < inputs.length; i++) { if(inputs[i].type.tolowercase() == 'radio') { if (inputs[i].checked){ alert('checked radio buttons value is:' + inputs[i].value); } } }
Comments
Post a Comment