RandomClown Posted November 27, 2008 Share Posted November 27, 2008 (edited) for about 2 hours now, this bit of code has been fuking with me. I have looked it up, but no guide fixes it. I cannot make this simple thing work! <form id="Menu" method="post" action=""><input name="Height1" type="text" size="10" value="FUK!"></form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.Menu.Height1.value="OMFG WORKS!"; } </script> Ohh, in other site forums, when talking code debugging, people usu. make guesses & leave. The guesses usu. fail, depending on the difficulty of the coding, making my question last another couple days... If you dont mind, could you try your theories before posting? Thanks for reading. **EDIT** Just to remind, the code would be over 1000 lines, so this is an isolation of the code & I changed the values cause its annoying me. Edited November 27, 2008 by RandomClown Quote Link to comment Share on other sites More sharing options...
Serganator Posted November 27, 2008 Share Posted November 27, 2008 Here you go just small little things I hope This Help <input name="Height1" type="text" size="10" value="FUK!"> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ parent.Height1.value="Ok It's fix"; // you can use either height1.value or parent.height1 //if your are to use a frame //parent.frame['framename].height1 } </script> Quote Link to comment Share on other sites More sharing options...
0xC0FF33 Posted November 27, 2008 Share Posted November 27, 2008 Try this: <form id="Menu" method="post" action=""><input id="Height1" name="Height1" type="text" size="10" value="FUK!"></form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!"; } </script> I had some problems, too, but the getElementById() function helped. Also you should not try to access Elements directly. User getElementByName(), getElementById() or getElementsByTag() functions. Quote Link to comment Share on other sites More sharing options...
RandomClown Posted November 27, 2008 Author Share Posted November 27, 2008 I tried the code but it did not work for me. T~T Also, what did you mean by "You should not try to access Elements directly."? Using element ID <body> <form Id="Menu" method="post" action=""> <input Id="Height1" type="text" size="10" value="FUK!"> </form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!"; } </script></body> No ID, using Name <body> <form name="Menu" method="post" action=""> <input name="Height1" type="text" size="10" value="FUK!"> </form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementByName("Menu").getElementByName("Height1").value="OMFG WORKS!"; } </script></body> No difference? http://hakhouse.blogspot.com/ Quote Link to comment Share on other sites More sharing options...
Serganator Posted November 27, 2008 Share Posted November 27, 2008 I tried the code but it did not work for me. T~T Also, what did you mean by "You should not try to access Elements directly."? Using element ID <body> <form Id="Menu" method="post" action=""> <input Id="Height1" type="text" size="10" value="FUK!"> </form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!"; } </script></body> No ID, using Name <body> <form name="Menu" method="post" action=""> <input name="Height1" type="text" size="10" value="FUK!"> </form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementByName("Menu").getElementByName("Height1").value="OMFG WORKS!"; } </script></body> No difference? http://hakhouse.blogspot.com/ I'm not sure about You should not try to access Elements directly. But here's a few more ways to do it. I have tried those on my local Machine with no problem The <form> is not needed but i did it anyway you just need to uncomment the one you like Let me know How this works for you <body> <form Id="Menu" name = "Menu" method="post" action=""> <input Id="Height1" Name= "Height1" type="text" size="10" value="Fix ME"> </form> <input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."> <script type='text/javascript'> function Save(){ document.getElementById('Menu').Height1.value="it works"; //document.Menu.Height1.value="It works also"; //Menu.Height1.value="it works"; // Menu.Height1.size = "59"; // document.Menu.Height1.value ="It Now Works"; //document.getElementById('Height1').value="WORKS!"; // Menu.elements["Height1"].value = "IT works"; } </script></body> Quote Link to comment Share on other sites More sharing options...
RandomClown Posted November 28, 2008 Author Share Posted November 28, 2008 I tried them & most of them failed, but super thanks! [1 of the 6 works in my real code] I have working codes now! Woot!!!! Ohh, javascript fails completely if I add a "name" & "id" to the same tag. That means no <input Id="Height1" Name="Height1"> weird. Quote Link to comment Share on other sites More sharing options...
Strife25 Posted November 28, 2008 Share Posted November 28, 2008 You generall should not ever give the same value to "id" and "name" attributes because the IE interpreter will also look at the name attributes when one calls getElementById http://www.456bereastreet.com/archive/2008...ernet_explorer/ Quote Link to comment Share on other sites More sharing options...
Bit Hunter Posted December 30, 2008 Share Posted December 30, 2008 When ever i have any problem with JavaScript i surf around on JavaScriptKit.com, and usually get an answer, and learn in the process... Quote Link to comment Share on other sites More sharing options...
firefox Posted January 2, 2009 Share Posted January 2, 2009 I haven't seen a response yet... There are 2 ways you can do this. OPTION 1 - More than 1 form tag <form name="Menu" method="post" action=""> <input name="Height1" type="text" size="10" value="Change Me"> <input type="button" onclick="Save()" style="color:ff0000" value="Change me."> </form> <script type="text/javascript" language="javascript"><!--// function Save(){ //document.<form-name>.<input-name> document.Menu.Height1.value = "This has been changed!"; } //--> </script> OPTION 2 - Unique IDs I have never had any issues with the getElementById function as mentioned on this page and this is usually most compatible with all browsers. You can use this, just make sure the tag has an id element and that it is a unique name. I always use getElementById. <form name="Menu" method="post" action=""> <input name="Height1" id="Height1" type="text" size="10" value="Change Me"> <input type="button" onclick="Save()" style="color:ff0000" value="Change me."> </form> <script type="text/javascript" language="javascript"><!--// function Save(){ //document.getElementById("<input-id>") document.getElementById("Height1").value = "This has been changed!"; } //--> </script> Hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.