Jump to content

JavaScript Write to textbox


RandomClown

Recommended Posts

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 by RandomClown
Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Try this:

&lt;form id="Menu" method="post" action=""&gt;&lt;input id="Height1" name="Height1" type="text" size="10" value="FUK!"&gt;&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;

&lt;script type='text/javascript'&gt;
function Save(){
    document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!";
}
&lt;/script&gt;

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.

Link to comment
Share on other sites

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

&lt;body&gt;
&lt;form Id="Menu" method="post" action=""&gt;
    &lt;input Id="Height1" type="text" size="10" value="FUK!"&gt;
&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;

&lt;script type='text/javascript'&gt;
function Save(){
    document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!";
}
&lt;/script&gt;&lt;/body&gt;

No ID, using Name

&lt;body&gt;
&lt;form name="Menu" method="post" action=""&gt;
    &lt;input name="Height1" type="text" size="10" value="FUK!"&gt;
&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;

&lt;script type='text/javascript'&gt;
function Save(){
    document.getElementByName("Menu").getElementByName("Height1").value="OMFG WORKS!";
}
&lt;/script&gt;&lt;/body&gt;

No difference?

http://hakhouse.blogspot.com/

Link to comment
Share on other sites

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

&lt;body&gt;
&lt;form Id="Menu" method="post" action=""&gt;
    &lt;input Id="Height1" type="text" size="10" value="FUK!"&gt;
&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;

&lt;script type='text/javascript'&gt;
function Save(){
    document.getElementById("Menu").getElementById("Height1").value="OMFG WORKS!";
}
&lt;/script&gt;&lt;/body&gt;

No ID, using Name

&lt;body&gt;
&lt;form name="Menu" method="post" action=""&gt;
    &lt;input name="Height1" type="text" size="10" value="FUK!"&gt;
&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;

&lt;script type='text/javascript'&gt;
function Save(){
    document.getElementByName("Menu").getElementByName("Height1").value="OMFG WORKS!";
}
&lt;/script&gt;&lt;/body&gt;

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

&lt;body&gt;
&lt;form Id="Menu" name = "Menu" method="post" action=""&gt;
    &lt;input Id="Height1" Name= "Height1" type="text" size="10" value="Fix ME"&gt;
&lt;/form&gt;

&lt;input type="button" onclick="Save()" style="color:ff0000" value="Plz work..."&gt;


&lt;script type='text/javascript'&gt;
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";
}
&lt;/script&gt;&lt;/body&gt;

Link to comment
Share on other sites

  • 1 month later...

I haven't seen a response yet...

There are 2 ways you can do this.

OPTION 1 - More than 1 form tag

&lt;form name="Menu" method="post" action=""&gt;
&lt;input name="Height1" type="text" size="10" value="Change Me"&gt;
&lt;input type="button" onclick="Save()" style="color:ff0000" value="Change me."&gt;
&lt;/form&gt;

&lt;script type="text/javascript" language="javascript"&gt;&lt;!--//
function Save(){
    //document.&lt;form-name&gt;.&lt;input-name&gt;
    document.Menu.Height1.value = "This has been changed!";
}
//--&gt;
&lt;/script&gt;

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.

&lt;form name="Menu" method="post" action=""&gt;
&lt;input name="Height1" id="Height1" type="text" size="10" value="Change Me"&gt;
&lt;input type="button" onclick="Save()" style="color:ff0000" value="Change me."&gt;
&lt;/form&gt;

&lt;script type="text/javascript" language="javascript"&gt;&lt;!--//
function Save(){
    //document.getElementById("&lt;input-id&gt;")
    document.getElementById("Height1").value = "This has been changed!";
}
//--&gt;
&lt;/script&gt;

Hope this helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...