Hi everyone, I have looked around the web for the solution to this - and I have found 'solutions' in a sense, but I can't get them to work how I need them to. Basically, I think because the page reloads onchange the other function won't stick. If someone can confirm my concerns or provide a solution, I'd be grateful. Here's the relevant code: This is where I want the functions to be called, and as you can see, one already is - and that's working fine... <select name='address' id="address" onchange="document.location.href = 'stepthree.php?defaddress=' + this.value;"> Code (markup): However, I want to implement this into it: <script type="text/javascript"> function addressentry() { if (document.stdaddress.address.value == '1') { document.form.line1.disabled=true; // return false; // not sure this line is needed } else { document.form.line1.disabled=false; // return false; // not sure this line is needed } } </script> Code (markup): I have tried this, with no success: <select name='address' id="address" onchange="document.location.href = 'stepthree.php?defaddress=' + this.value; addressentry();"> Code (markup): Although it does look like the field flickers to 'disabled' and then becomes active again. I figure this is down to the page reloading, but if anyone can provide a solution, it'd be great!
So do you want to set document.form.line1.disabled=true; and then reload the page? Or call addressentry() after the page has reloaded?
Thanks for your reply. My fault (sorry admins!) - I kind of assumed it could go in either, since the file is a php file. Logically, I guess I want the addressentry() to be called on reload. That way it will disable fields which have been filled from the dropdown menu. How would I do this?
addressentry won't be called after the page reloads. There are ways to do it, in your HTML, by adding the function to run at the bottom of all your content (on step three). <body> <!--[All your HTML code goes here]--> <script type="text/javascript"> addressentry(); </script> </body> HTML: If you are trying to pass data on page to page, you are going to need to use cookies in PHP or Javascript. Or get/post.
I wouldn't call it via Javascript on reload. I'd look for the address param within PHP and set the disabled attribute as required. So on a reload on the element you want to disable add this to where the DISABLED attribute would normally go. if((isset($_GET['address'])) && ((int)$_GET['address'] == 1)) { echo 'DISABLED'; } PHP:
That would be a better way since it would gracefully degrade for users without scripts enabled. Though the proper HTML to output would be: $disabled = 'disabled="disabled"; ... echo '<input '.$disabled.' name="addressline1" />'; PHP: