Hi.

I have a textarea and i want my button to be enabled when the contents of the textarea is changed. But i don't want onchange method because even when i type even a letter it keeps firing the js function.
I got the contents of textarea from the database and i want to check if the contents are changed or not. if it is changed at last. i want to enable my button.

Xessa,

You need to decide on which event the "change validator" should fire.

You've found textarea.onchange (pseudo-code) to be disruptive so I suggest textarea.onblur as the next one to try. This will enable the button when focus moves from the text area to something else.

If you want, you can give focus to an element of your choice when the button becomes enabled to encourage the user in the "right direction". For this use element.focus() (pseudo-code again).

Let us know how it goes.

Airshow

I got the contents of textarea from the database and i want to check if the contents are changed or not. if it is changed at last. i want to enable my button.

guess for that you will have to
check the value of the text box
first on the ONFOCUS EVENT
and then on ONBLUR event.
and if they are not equal then change the disable property of the button....
let us know if you need help with the code..

when you get the database contents assuming the row is array $row
$row is assumed to have a value inserted into the html textareaif you create a javascript variable of $row you could compare textarea.value with that javascript variable onblur and enable the button
code as thought process only,

<script type='text/javascript'>
<!--
function checktext()
if document.textarea.value() != "<?php echo $row['textarea']; ?>" { enable_submit_button_of_some_kind  };
--></script>
<textarea rows='6' cols='60' onblur=checktext();><?php echo $row['textarea']; ?></textarea>

Well this is weird but onchange works.

in html onchange="itChanged()" in js file

function itChanged()
{
myForm.myButton.disabled = false;
}

This works and does not enable my button till i blur from the textarea...

Xessa,

But how about your original statement ....

But i don't want onchange method because even when i type even a letter it keeps firing the js function.

Is that no longer an issue?

Airshow

I put an alert(" ") in onChanged() function. it used to alert when i type but later it stopped. i don't know what happened? :confused:

That's code development! It has a mind of its own sometimes.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.