Forum Moderators: open

Message Too Old, No Replies

changing Javascript button

         

Gero_Master

3:47 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



Hi!

To make my site seem more alive, I think I could add a button that changes text when it is pressed:

Submit button inside a form says "submit", but after clicking it does:

-becomes disabled
-changes text to "wait..."
-submits the form

Can someone do that code?

Tomi

mehh

5:12 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



you want something like:
<body>
<script type="text/javascript">
function change_txtinform()
{
txt1="Hello";
txt2="Only me.";
if(document.form1.text.value==txt1)
{
document.form1.text.value=txt2;
}
else
{
document.form1.text.value=txt1;
}
return false;
}
</script>
<form name="form1" onSubmit="return change_txtinform()" >
<input type="text" value="Hello" name="text">
<input type="submit" value="Change The Text">
</form>
</body>

Gero_Master

6:21 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



That will be helpful, but i ment that the button would change it's own text

the other parts of the form would remain the same, only button changes.

and the button should go disabled after the click

mehh

8:54 am on Apr 3, 2006 (gmt 0)

10+ Year Member



how about this then:

<body>
<script type="text/javascript">
function change()
{
txt1="Please Wait...";
if(document.form2.text.value==txt1)
{
return false;
}
else
{
document.form2.text.value=txt1;
document.form2.text.disabled=true;
return false;
}
}
</script>
<form name="form2" onSubmit="return change()" action="somepage.php">
<input type="submit" name="text" value="Submit This Form">
</form>
</body>

Gero_Master

11:15 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Thank you! It's working now!