Matej Posted April 28, 2014 Share Posted April 28, 2014 Hello there , i'd like to ask a question. When there is <input type="text" Id="GG" name="topic" value ="hi"> it is the same when i write var x=document.getElementById("GG"); x.value and topic.value ? Thanks for answers Link to comment Share on other sites More sharing options...
davej Posted April 28, 2014 Share Posted April 28, 2014 The name becomes the key of a key-value pair when a form is submitted but for normal DOM accesses I think id is more efficient if you look up the benchmarks. You can google discussions on this topic... http://stackoverflow.com/questions/2435525/best-practice-access-form-elements-by-html-id-or-name-attribute Link to comment Share on other sites More sharing options...
Matej Posted April 28, 2014 Author Share Posted April 28, 2014 Well can you please explain why this doesnt work http://jsfiddle.net/35fQG/1/ (couldnt use forms) and this does function nastav(typ) { if (typ.value == "Zeleninový speciál") { document.forms["pizzaFormular"].druh.value = "zelenina"; } else if (typ.value == "Masový speciál") { document.forms["pizzaFormular"].druh.value = "maso"; } else if (typ.value == "Hawaii") { document.forms["pizzaFormular"].druh.value = "sunkaAnanas"; } } <body><form id="pizzaFormular" action="#" onsubmit="return false;"><p> <input type="button" onclick="nastav(zelenSpecial)" name="zelenSpecial" value="Zeleninový speciál"/><input type="button" onclick="nastav(masoSpecial)" name="masoSpecial" value="Masový speciál" /><input type="button" onclick="nastav(hawaii)" name="hawaii" value="Hawaii" /> </p><p>Druh pizzy: <select name="druh"><option value="syr" selected="selected">Sýrová</option><option value="zelenina">Zeleninová</option><option value="maso">S masem</option><option value="sunkaAnanas">Se šunkou a ananasem</option></select></p></form></body> Link to comment Share on other sites More sharing options...
davej Posted April 28, 2014 Share Posted April 28, 2014 Have you looked at... http://www.w3schools.com/jsref/dom_obj_select.asp http://www.w3schools.com/jsref/coll_select_options.asp http://www.w3schools.com/jsref/prop_select_selectedindex.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now