Jump to content

simple function does not work?


coderb

Recommended Posts

Hi All,

 

I must be doing something wrong. I have a from with an input field and button. On change of input field I want to disable the button.

 

this works:

<input name="subject" type="text" onchange="mailform.Print.disable = true;"/>

 

if I now change this to be executed in a function, it no longer works:

 

<input name="subject" type="text" onchange="Print_disable()"/>

 

<script language="javascript">

function Print_disable () {

alert("hello");

                mailform.Print.disable = true;

}

</script>

 

to confirm that this funciton is executed I added the alert. But my Print button is not disabled.

 

Any help appreciated, thanks.

 

 

 

Link to comment
Share on other sites

I'm no javascript expert, but try changing the name of the function to something else. Some languages don't allow you to start variables and functions with words like "Print". Change it to something random like banana to test this.

 

edit: Oops... if it was showing the alert before then it was not the name of the function causing the problem, ignore me!

Link to comment
Share on other sites

thanks for trying.  anyone else got any ideas? could it be a browser issue, could someone maybe test my code:

 

this works:

<form name="mailform" ...

<input name="subject" type="text" onchange="mailform.Printx.disabled = true;"/>

<input name="Printx" type="submit" value="Print Friendly">

 

this doesn't:

<head>

<script type="text/javascript">

function Printx_disable () {

mailform.Printx.disabled = true;

}

</script>

 

<form name="mailform" ...

<input name="subject" type="text" onchange="Printx_disable ()"/>

<input name="Printx" type="submit" value="Print Friendly">

Link to comment
Share on other sites

I would prefer looking the element up by id like

 

document.getElementById('PrintX').disabled = true; //if Printx is the id of the element

 

As to why what I wrote works, it is because the document.forms array holds all of the forms. you can assess your mailform by its name or index. then the form has an array of the elements that you can assess either way as well

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.